0

I am running on python 2.7.5. I am converting some bash script to python (learning as I coding) and I'm confused on which is the better solution? I need to copy files to a remote server and then run a script on that remote server using the file. I was using Popen

ssh = subprocess.Popen(["ssh", desthost, "cd {}; {} {}".format(remote_dir, scriptname, filename)]

But it doesn't read my cd. I see that I can use call but I am not clear on if I can get error output from it like I could if I used popen. I keep seeing fabric being mentioned but I didn't know it this could really be done in a one liner. Any advice is appreciated.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • You should use the Paramiko library to use ssh from Python. – Barmar Mar 01 '22 at 21:19
  • You shouldn't be using Python 2.x, it has been EOLed. Upgrade to 3.x. – Barmar Mar 01 '22 at 21:21
  • The `ssh` command inherits its standard output and standard error from your Python process itself. See the documentation for the `subprocess` module for how to create a pipe the `ssh` will write to and your Python code can read from instead. – chepner Mar 01 '22 at 21:45
  • @Barmar, you're right, I did not notice the `ssh`, I will delete my comment to not confuse others. – Marya Mar 01 '22 at 21:49
  • Thanks, I had the sys admins upgrade my python version. I will look at paramiko again. It seemed to be overkill for the commands i needed. – mrlddst Mar 02 '22 at 15:05

0 Answers0