I am using subprocess.Popen to execute an OS command. Here is what I am trying to emulate in my code:
ssh -T myhost < /path/to/some/file
It works fine like this:
def runWorkerCode(filer, filename): command = "/usr/bin/ssh -T " + filer + " < /devel/myscript" try: p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) out, _ = p.communicate() except Exception: print "Error: %s" % Exception sys.exit(1) return out.rstrip().split('\n')
But the following calls to Popen do not work:
p = subprocess.Popen(["/usr/bin/ssh", "-T", filer, "<", "/devel/myscript"], stdout=subprocess.PIPE, shell=True) p = subprocess.Popen(["/usr/bin/ssh -T", filer, "< /devel/myscript"], stdout=subprocess.PIPE, shell=True)
I tried a few other combinations but only method I can get to work is defining the command variable and only providing it to
Popen(). I've also tried
The first method works but the latter approach seems "cleaner" to me.
Popen allow me to specify the arguments in a list?