Python to call commands, e.g. "find , perl scripts , nmap , and others" is this possible?

Ken Seehof 12klat at sightreader.com
Tue Jun 6 18:32:29 EDT 2000


I'm running PythonWin
I tried python from the command line.  The process hangs.

>>> import os
>>> os.popen('dir').readlines()
 (hangs . . .)

IDLE gives the same results as PythonWin:

>>> import os
>>> os.popen('dir').readlines()
Traceback (innermost last):
  File "<pyshell#1>", line 1, in ?
    os.popen('dir').readlines()
OSError: (0, 'Error')

Apparently you are right about Window pipes.  <MSJAB> Not surprising.
Microsoft would probably get rid of the command line completely if not
for its legacy value.  It's hard to control the world when the prolls
have access to a usable command shell. </MSJAB> :-)

-- Ken Seehof
kens at sightreader.com
starship.python.net/crew/seehof
Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!

Emile van Sebille wrote:

>  Ken, Are you trying this in IDLE?  I get the same error there.If so,
> try starting python from within a dos window andsee if that makes a
> difference.  Pipes in winxx are somewhatflakey as I understand.
> Emile van Sebille
> emile at fenx.com
> -------------------
> ----- Original Message -----
> From: Ken Seehof
> To: Emile van SebilleCc: python-list at python.orgSent: Thursday, June
> 01, 2000 5:25 PMSubject: Re: Python to call commands, e.g. "find ,
> perl scripts , nmap , and others" is this possible?
>  On NT I get:
>
> >>> mylist = os.popen('dir').readlines()
> Traceback (innermost last):
>   File "<interactive input>", line 1, in ?
> OSError: (0, 'Error')
>
> (same thing with any command)
>
> popen (command[, mode[, bufsize]])
>     Open a pipe to or from command. The return value is an open
>     file object connected to the pipe, which can be read or written
>     depending on whether mode is 'r' (default) or 'w'. The bufsize
>     argument has the same meaning as the corresponding argument
>     to the built-in open() function. The exit status of the command
>     (encoded in the format specified for wait()) is available as the
>     return value of the close() method of the file object, except that
>
>     when the exit status is zero (termination without errors), None is
>
>     returned. Availability: Unix, Windows.
>
> - Ken Seehof
>
> Emile van Sebille wrote:
>
>> Jim, Take a look at os.popen, as in: import osmylist =
>> os.popen('locate myname').readlines()for eachfile in mylist: do
>> something with eachfileHTH,
>> Emile van Sebille
>> emile at fenx.com
>> -------------------
>> ----- Original Message -----
>> From: Jim
>> To: python-list at python.orgSent: Thursday, June 01, 2000 9:44
>> AMSubject: Python to call commands, e.g. "find , perl scripts , nmap
>> , and others" is this possible?
>> Dear list,
>>
>> I'm new to Python, and I'm sorry if I'm asking about anything that
>> has been
>> already discussed.
>>
>> I would like to use Python to call commands, e.g. "find , perl
>> scripts  , nmap , and others" is this possible?
>>
>> I do not need GUI. All I need is to link the out put and work with
>> it. Is perl or shell scripts my only
>> answer?
>>
>> jim
>>
>> --
>> Proprietary & Confidential.  The information transmitted is intended only for the person or entity to whom it is addressed and may
>> contain confidential and/or privileged material.  Any review, retransmission, dissemination, or other use of, or taking of any
>> action in reliance upon, this information by persons or entities other than the intended recipient is prohibited.  If you received this in error, please
>> contact the sender and delete the material from any computer.
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20000606/75764b0a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 12klat.vcf
Type: text/x-vcard
Size: 343 bytes
Desc: Card for Ken Seehof
URL: <http://mail.python.org/pipermail/python-list/attachments/20000606/75764b0a/attachment.vcf>


More information about the Python-list mailing list