通过SSH命令执行python到树莓派(使用Csharp和SharpSSH)

本文关键字:使用 Csharp SharpSSH 命令 SSH 执行 python 通过 | 更新日期: 2023-09-27 18:08:12

我有一个通过ssh执行python脚本的问题(使用c#和SharpSSH)。

我有连接,可以写简单的命令,如"startx"answers"sudo shutdown…"

当我试图运行一个python脚本冻结程序,什么都没有发生。我已经尝试了完全相同的程序与"腻子",它的工作如预期的。

python脚本运行,我得到数据(打印'No Laser, fast movement: Dx=', stepx, ' Dy=', stepy),这对我的应用程序很重要。

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上)

        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";  
        }

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

通过SSH命令执行python到树莓派(使用Csharp和SharpSSH)

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

现在可以工作了。

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