0

我在通过 ssh 执行 python 脚本时遇到问题(使用 c# 和 SharpSSH)。

我有连接并且可以编写简单的命令,例如“startx”和“sudo shutdown ...”

当我尝试运行 python 脚本时,程序会冻结并且没有任何反应。我用“putty”尝试了完全相同的程序,它按预期工作。

python脚本运行,我得到数据(打印'无激光,快速移动:Dx =',stepx,'Dy =',stepy)whitch对我的应用程序很重要。

C# SharpSSH 连接

            ssh = new SshStream(host, user, password);

            //Set the end of response matcher character
            ssh.Prompt = "#";
            //Remove terminal emulation characters
            ssh.RemoveTerminalEmulationCharacters = true;

            //Reading from the SSH channel
            string response = ssh.ReadResponse();
            return response;

C# 启动 Gcode_executer.py 不起作用并冻结程序(在 pc 上)树莓派不运行 python 文件

        try
        {
            ssh.Write("sudo python cnc/Gcode_executer.py");  // Write ssh to RPI
                                                             // works it in putty
            if (ssh.CanRead == true)
            {
                return ssh.ReadResponse(); // return string from terminal from RPI
            }
            else
            {
                return "No response";
            }
        }
        catch
        {
            return "Catch NO response";  
        }

我能做些什么来解决这个问题?

4

2 回答 2

0

现在可以了。

我的 python 脚本有子文件。因此必须 cd 进入文件夹,直到它有正确的子文件路径

于 2014-06-23T05:44:15.843 回答
0

尝试编写一个运行 .py 文件并调用该 shell 脚本的 shell 脚本(在 pi 上)。

于 2014-06-19T22:26:33.193 回答