Assistance in understanding the sub-Process module

vijay swaminathan swavijay at gmail.com
Fri May 13 07:03:07 EDT 2011


Hi Gurus,

I'm new to Python programming and in the process of learning the sub process
module.

I went through the python documentation
http://docs.python.org/library/subprocess.html and I have the following
queries

1. The class definition as per the documentation is:
*class *subprocess.Popen(*args*, *bufsize=0*, *executable=None*, *stdin=None
*, *stdout=None*, *stderr=None*, *preexec_fn=None*, *close_fds=False*, *
shell=False*, *cwd=None*, *env=None*, *universal_newlines=False*, *
startupinfo=None*, *creationflags=0*)
*args* should be a string, or a sequence of program arguments.

so I assume that args can be a string or a list with first item of the list
being the program to execute.

so on the python IDLE, I executed this command,

>>> subprocess.Popen('cmd.exe')
<subprocess.Popen object at 0x00F5AA50> which opened up a command prompt.

when I give this as a list, as below it throwed this error.

>>> subprocess.Popen(['cmd.exe', 'dir'])
Traceback (most recent call last):
  File "<pyshell#29>", line 1, in <module>
    subprocess.Popen(['cmd.exe' 'dir'])
  File "C:\Python26\lib\subprocess.py", line 623, in __init__
    errread, errwrite)
  File "C:\Python26\lib\subprocess.py", line 833, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
>>>

I would assume that a list is accepted as part of the args and first being
the program (cmd.exe) and the rest being the arguments... please correct me
If i misunderstood.

Thanks,


-- 
Vijay Swaminathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110513/311794be/attachment.html>


More information about the Python-list mailing list