How to get shell screen out from python?
D-Man
dsh8290 at rit.edu
Wed Jan 24 22:03:46 EST 2001
On Wed, Jan 24, 2001 at 09:05:28PM -0500, Changsen Xu wrote:
| Hi,
|
| Now I wish to get the output from running a shell command, I
| can't find an easy way in python but use pipe:
| p=popen('lp *.ps'); t=p.read(); p.close()
This could be written as :
t = popen( "lp *.ps" ).read()
or you could make a function to do that:
def pipe_read( command ) :
return popen( command ).read()
then call it :
t = pipe_read( "lp *.ps" )
|
| while in tcsh, it may just be:
| set t = `lp *.ps`
It is common for shell scripting languages to execute external
programs rather than implement things in the shell itself. Perl has
this backtick syntax for executing an external command.
|
| Any of you can teach me an easier way in python ?
|
| Thanks,
|
HTH,
-D
More information about the Python-list
mailing list