views:

57

answers:

2

I am trying to call remote (ssh) commands using the subprocess.call function like this.

import shlex
from subprocess import call
cmd1='ssh [email protected] mkdir temp'
cmd2='scp test.txt [email protected]:temp'

call(shlex.split(cmd1))
call(shlex.split(cmd2))

When I call the above, the mkdir does not seem to execute - although the documentation for subprocess.call says it waits for execution before returning. The latency of the individual ssh calls is about 0.5 seconds. It seems to work fine on the gigabit LAN where the latency is almost zero.

However it seems to work fine when the calls are made like this:

call(shlex.split(cmd1)) &  call(shlex.split(cmd2))

What is the problem with the first approach?

Thank you, Miliana

A: 

It looks like you don't look for the result of call in the first method.

if call(shlex.split(cmd1))!=0:
    call(shlex.split(cmd2))
Xavier Combelle
I tried this (checking for zero, nonzero return code) , but it doesnt seem to work either.
Miliana Bregovic
Xavier Combelle
obviously they arent exactly same implementation wise
Miliana Bregovic
A: 

Your problematic version always works for me. I would think this is a network problem especially since you indicate that it works in gigabit LANs.

kashif