OS specific command in Python

diffuser78 at gmail.com diffuser78 at gmail.com
Wed Jun 21 10:13:13 EDT 2006


Hi Avell,

I want to communicate using subprocess module but my task is a little
different. May be you can guide me.

I have a linux box, from where I remotely execute all the commands. The
remote machine is windows machine. I installed an OpenSSH server for
windows to send the shutdown command. I setup the public keys in such a
way that I could login to SSH server without using password.

I used

import os
os.system('ssh Admin at IP_ADDRESS shutdown -s')


I was wondering how can I interact with an application . Since you
mentioned about subprocess module, I want a ability that my PYthon
script can actually interact with the windows box and launch and close
application there remotely.

Any suggestions on how to do this ?

Every help is appreciated.

Thanks for your time

Avell Diroll wrote:

> This is an simple way to proceed if you don't need your python script to
> know what happens to the launched process ...
> When you need to :
> * send some input to the command from the python script after it is launched
> * get the output of the command in your python script
> * get the pid associated to your command
> * wait for your command to finish
> * pipe some shell commands
> * ...
> you should use the subprocess module.
>
> Here is a quick example from the Python Reference Library :
> http://docs.python.org/lib/node242.html
>
> ##Shell Script :
> output=`dmesg | grep hda`
>
>
> ##Python Script :
> from subprocess import Popen
> p1 = Popen(["dmesg"], stdout=PIPE)
> p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
> output = p2.communicate()[0]




More information about the Python-list mailing list