Thanks a ton for the prompt reply & the great suggestions, Dave.<div><br></div><div>1.   A colleague gave this exact same suggestion</div><div>os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2 has spaces" arg3') </div>
<div><br></div><div>I was thinking spaces is my problem, so i initially tested the following (no ssh)</div><div>os.system('python remote.py arg1 "arg 2 has spaces" arg3')  & it works :)</div><div><br>
</div><div>But sadly, 
os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2 has spaces" arg3')   does not :(</div><div><br></div><div>2. Also, you mentioned os.exec</div><div>Which would you recommend ? </div><div>os.system or os.exec ?</div>
<div><br></div><div>Thanks a lot,</div><div><br></div><div>cheers</div><div>ashish</div><div><br></div><div><br><br><div class="gmail_quote">On Thu, Sep 20, 2012 at 12:54 AM, Dave Angel <span dir="ltr"><<a href="mailto:d@davea.name" target="_blank">d@davea.name</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 09/19/2012 02:47 PM, ashish makani wrote:<br>
> Hi PyTutor Folks<br>
><br>
> Here is my situation<br>
><br>
</div>> 1. I have two machines. Lets call them *local & remote.*<br>
<div class="im">> Both run ubuntu & both have python installed<br>
><br>
</div>> 2. I have a python script, *local.py*, running on *local *which needs to<br>
<div class="im">> pass arguments ( 3/4 string arguments, containing whitespaces like spaces,<br>
</div>> etc ) to a python script, *remote.py* running on *remote* (the remote<br>
<div class="im">> machine).<br>
><br>
> I have the following questions:<br>
><br>
> 1. What's the best way to accomplish my task ?<br>
> I have researched quite a bit & so far found really conflicting & complex<br>
> workarounds.<br>
><br>
> I googled & found people using several libraries to accomplish ssh to<br>
> remote machine & execute a command on remote machine.<br>
</div>> paramiko <<a href="http://www.lag.net/paramiko/" target="_blank">http://www.lag.net/paramiko/</a>> ( now forked into the ssh<br>
> moduke<<a href="https://github.com/bitprophet/ssh" target="_blank">https://github.com/bitprophet/ssh</a>>),<br>
> fabric <<a href="http://docs.fabfile.org/en/1.4.3/index.html" target="_blank">http://docs.fabfile.org/en/1.4.3/index.html</a>>,<br>
> pushy<<a href="http://packages.python.org/pushy/" target="_blank">http://packages.python.org/pushy/</a>>,etc<br>
<div class="im">><br>
> People who have used any of these libraries, which one would you recommend,<br>
> as the most apt (simple & easy to use, lightweight, best performance, etc)<br>
> for my situation ?<br>
><br>
> 2. I would prefer a solution, which does NOT require the installation of<br>
> extra libraries on the local & remote machines.<br>
> If installing external librar<br>
><br>
> 3. Has anybody been able to do this using os.system ?<br>
><br>
> I tried this<br>
>>>> import os<br>
</div>>>>> *os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3")*<br>
> *<br>
<div class="im">> *<br>
> This worked, but if the arguments i tried to pass, had spaces, i was not<br>
> able to 'escape' the spaces.<br>
><br>
> Any & all explanations/links/code<br>
> snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor<br>
> community would be greatly appreciated.<br>
><br>
> Thanks a ton<br>
><br>
> cheers<br>
> ashish<br>
><br>
> email :<br>
> ashish.makani<br>
> domain:<a href="http://gmail.com" target="_blank">gmail.com</a><br>
><br>
</div>> *“The only way to do great work is to love what you do. If you haven’t<br>
<div class="im">> found it yet, keep looking. Don’t settle. As with all matters of the heart,<br>
</div>> you’ll know when you find it.” - Steve Jobs (1955 - 2011)*<br>
><br>
><br>
<br>
Since you prefer not installing any optional libraries, I'll just talk<br>
about your os.system() mechanism. Is that adequate for you, other than<br>
the problem with spaces?<br>
<br>
If so, then why not test it with the real ssh, to figure out where the<br>
quotes need to be to handle the spaces. Then once you have it working,<br>
use single quotes around the whole thing when calling os.exec().<br>
<br>
Something like (all untested):<br>
<br>
os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2 has spaces" arg3')<br>
<br>
<br>
Or, more likely, build the arguments in separate variables, and use<br>
<br>
os.system( 'ssh remoteuser@remote python remote.py "%s" "%s" "%s"' %<br>
(arg1, arg2, arg3) )<br>
<br>
that will fail if the argn already has quotes in it. You can get much<br>
fancier with encoding, which will add backslashes in front of some<br>
characters, etc. But keep it simple if you can.<br>
<br>
I ought to give the obligatory: use the multiprocess module instead of<br>
os.exec, but if something works for you, I'm not going to argue.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
<br>
--<br>
<br>
DaveA<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>
</div>