simple question

John Leach bbosware at vic.bigpond.net.au
Mon Dec 6 18:25:25 EST 1999


It could be just that you want to do

import os
os.system(cmd)

eg os.system('ls')

or
os.fork(cmd)

I asked question here on ssh a couple of weeks back and received a lot of
interesting suggestions - you may like to go to Deja News and have a look at
the thread.

One suggestion was to use popen and I enclose the manual pages for that (I
have not attempted this yet):-


>From the  Python Library Reference

8.14 popen2 -- Subprocesses with accessible standard I/O streams

Availability: Unix, Windows.

This module allows you to spawn processes and connect their
input/output/error pipes and obtain their return codes.

The primary interface offered by this module is a pair of factory functions:

popen2 (cmd[, bufsize])
Executes cmd as a sub-process. If bufsize is specified, it specifies the
buffer size for the I/O pipes. Returns (child_stdout, child_stdin).

popen3 (cmd[, bufsize])
Executes cmd as a sub-process. If bufsize is specified, it specifies the
buffer size for the I/O pipes. Returns (child_stdout, child_stdin,
child_stderr).
The class defining the objects returned by the factory functions is also
available:

Popen3 (cmd[, capturestderr[, bufsize]])
This class represents a child process. Normally, Popen3 instances are
created using the factory functions described above.
If not using one off the helper functions to create Popen3 objects, the
parameter cmd is the shell command to execute in a sub-process. The
capturestderr flag, if true, specifies that the object should capture
standard error output of the child process. The default is false. If the
bufsize parameter is specified, it specifies the size of the I/O buffers
to/from the child process.

----------------------------------------------------------------------------
----
   Python Library Reference
----------------------------------------------------------------------------
----

8.14.1 Popen3 Objects
Instances of the Popen3 class have the following methods:

poll ()
Returns -1 if child process hasn't completed yet, or its return code
otherwise.

wait ()
Waits for and returns the return code of the child process.
The following attributes of Popen3 objects are also available:

fromchild
A file object that provides output from the child process.

tochild
A file object that provides input to the child process.

childerr
Where the standard error from the child process goes is capturestderr was
true for the constructor, or None.


----------------------------------------------------------------------------
----
   Python Library Reference
----------------------------------------------------------------------------
----









Markus Weimer wrote in message <384C106A.5BA89AF4 at gmx.net>...
>Hi!
>
>I'm starting to learn python and would like to write a small gtk-based
>wrapper for ssh. I've got a simple gui and now I want the gui to start
>ssh. I build a string for the commandline. So, how do I parse this to
>the os? Iwould look at www.python.org, but it's down. So please help me.
>
>Thanks in advance
>
>
>Markus Weimer
>
>--
>Markus Weimer
>markus.weimer at gmx.net
>www.av.wh.tu-darmstadt.de/homes/markus
>
>
>






More information about the Python-list mailing list