-3

I have a python program that SSH's into a system, runs a .py script and has to cat a file.

Once it has run the .py script after SSHing into the remote system, I have to manually hit "return" for the cat program to display the contents of the file. This is because the program is stuck at that point.

What I have looks like this:

s = subprocess.Popen(["../../run.py", "cat", "../../file.xml")
user2921139
  • 1,669
  • 4
  • 17
  • 25
  • 1
    You forgot to show us what `../../run.py` is. And the majority of your script. – Bill Lynch Oct 29 '14 at 02:23
  • That script does nothing, but just SSH's into a remote machine. Just to clarify, the SSH is a password less login (configured using SSH-keygen) – user2921139 Oct 29 '14 at 02:28

1 Answers1

0

If I understand correctly you want to run a python script, wait for it to finish, and then cat a file? If that is correct, you would have to use two subprocess calls. Your line as written is running run.py with arguments cat and ../../file.xml

Why does run.py wait for user input? My first choice would be to change that. With that not being an option, I may go for something like

echo "/n" > python ../../run.py

I am not sure what your plan is behind all of this :) If this is the extent of what you are trying to do, a shell script would be a better choice. Something like this-

ssh user@myserver -c "echo "/n" > python ../../run.py; cat ../../file.xml"

If it is something else, the docs for the subprocess module can explain lots of different ways of entering input into and reading output from a subprocess.

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

Paul Becotte
  • 9,767
  • 3
  • 34
  • 42