Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5300
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <mail@timgolden.me.uk> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'own.': 0.04; 'subject:module': 0.04; 'string,': 0.05; 'think,': 0.05; 'args': 0.07; 'python': 0.07; 'arguments.': 0.09; 'correct.': 0.09; 'executed': 0.09; 'from:addr:timgolden.me.uk': 0.09; 'from:name:tim golden': 0.09; 'message-id:@timgolden.me.uk': 0.09; 'subprocess': 0.09; 'underlying': 0.09; '>>>': 0.12; 'wrote:': 0.14; '(windows)': 0.16; '__init__': 0.16; 'errread,': 0.16; 'executables': 0.16; 'idle,': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'shell=true)': 0.16; 'so...': 0.16; 'traceback': 0.16; '(most': 0.16; 'ignore': 0.16; 'shell': 0.19; 'command': 0.19; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; '(or': 0.22; 'header:In-Reply-To:1': 0.22; "aren't": 0.22; 'cc:addr:python-list': 0.22; 'right.': 0.22; 'specified': 0.22; 'last):': 0.23; 'library.': 0.25; 'assume': 0.25; 'definition': 0.29; 'string': 0.29; 'skip:" 30': 0.29; 'class': 0.29; 'subject:skip:u 10': 0.29; 'list': 0.30; 'cc:addr:python.org': 0.31; 'cmd': 0.31; 'preferable': 0.31; 'tjg': 0.31; 'does': 0.31; 'however,': 0.31; 'import': 0.32; 'received:192': 0.34; 'actually': 0.34; 'file': 0.35; 'open': 0.35; 'header:User-Agent:1': 0.35; '"",': 0.35; 'leaves': 0.35; 'quotes': 0.35; 'usually': 0.36; 'doing': 0.36; 'running': 0.36; 'error.': 0.36; 'getting': 0.36; 'list,': 0.36; 'received:192.168': 0.37; 'rest': 0.37; 'should': 0.37; 'exactly': 0.37; 'run': 0.37; 'commands': 0.38; 'sequence': 0.38; 'less': 0.38; 'would': 0.40; 'from:addr:mail': 0.60; 'opened': 0.60; 'give': 0.61; 'and,': 0.63; 'below': 0.63; 'want:': 0.84; 'to:none': 0.92 |
| Date | Fri, 13 May 2011 13:44:03 +0100 |
| From | Tim Golden <mail@timgolden.me.uk> |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 |
| MIME-Version | 1.0 |
| CC | python-list@python.org |
| Subject | Re: Assistance in understanding the sub-Process module |
| References | <BANLkTimWZUynKdfYUoSgzB5O1YQ93QnJpA@mail.gmail.com> |
| In-Reply-To | <BANLkTimWZUynKdfYUoSgzB5O1YQ93QnJpA@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1514.1305290653.9059.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305290653 news.xs4all.nl 81485 [::ffff:82.94.164.166]:56256 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5300 |
Show key headers only | View raw
On 13/05/2011 12:03, vijay swaminathan wrote:
> 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.
That's more or less correct. A list is usually preferable as it leaves
the heavy-lifting of getting the quotes right to the underlying library.
> 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
Well I would actually have expected it to open a command
prompt and do nothing else. If you do this in a (Windows)
command prompt:
cmd /?
you can see that the way to run a command from with a command
shell is to use: cmd /c <whatever> (or /k which leaves the
console running afterwards). Note that you only even need to
launch cmd for internal commands which aren't executables in
their own right. ie you don't need to do cmd /c notepad since
notepad can run on its own.
So doing cmd <whatever> will just run cmd and, I think,
ignore the rest of the line. You actually want:
import subprocess
subprocess.Popen (["cmd", "/c", "dir"])
However, that is exactly what passing shell=True to Popen
does for you so...
import subprocess
subprocess.Popen ("dir", shell=True)
# or subprocess.Popen (["dir"], shell=True)
TJG
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Assistance in understanding the sub-Process module Tim Golden <mail@timgolden.me.uk> - 2011-05-13 13:44 +0100
csiph-web