1

I have a python script that establishes ssh connected using os.system() function :

def livestream():
   os.system('ssh -X [email protected]')
   os.system('cd Desktop') #doesn't get executed on remote machine

I know that os.system() executes commands on the same machine.

Further, I need to execute a program present on the remote machine.

My question is how do I execute bash commands in python once ssh connection is established?

2 Answers 2

2
def livestream():
   os.system('ssh -X [email protected] "cd Desktop"')
Sign up to request clarification or add additional context in comments.

1 Comment

I need to manually type the password and then i get this nehal@nehal-300E4Z-300E5Z-300E7Z:~$ exit logout Connection to 192.168.0.2 closed. sh: 1: cd darknet: not found sh: 1: ./darknet detector demo cfg/coco.data cfg/yolo.cfg final.weights: not found
1

You can use the call method from the subprocess module.

https://docs.python.org/2/library/subprocess.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.