Lars90er
Lars90er

Reputation: 1

Executed python via SSH commands to raspberry pi (using Csharp and SharpSSH)

I have a problem with executing python script over ssh (using c# and SharpSSH).

I have connection and can write simple commands like "startx" and "sudo shutdown ..."

When I try to run a python script freezes the program and nothing happens. I have tried exactly the same procedure with "putty" and it work as expected.

The python script runs and i get data (print 'No Laser, fast movement: Dx=', stepx, ' Dy=', stepy) whitch is importen for my application.

C# SharpSSH connection

            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# start Gcode_executer.py does not work and freezes program(on pc) raspberry pi dont run python file

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

What I can do to solve the problem?

Upvotes: 0

Views: 1692

Answers (2)

Lars90er
Lars90er

Reputation: 1

It works now.

My python script have sub files. therefore must be cd Into the folder until it has the correct path to sub files

Upvotes: 0

a_river_in_canada
a_river_in_canada

Reputation: 299

Try writing a shell script (on the pi) that runs the .py file and calling that shell script.

Upvotes: 0

Related Questions