] subprocess.call list vs. str argument
On 26 February 2014 08:50, Albert-Jan Roskam fo...@yahoo.com wrote:
Yesterday evening (it was *late* so forgive me if I wrong) I realized that
part of my confusion was also caused by the fact that I ran my code in Idle.
If I called subprocess.call with a list
?
~~
On Tue, 2/25/14, eryksun eryk...@gmail.com wrote:
Subject: Re: [Tutor] subprocess.call list vs. str argument
To: Dave Angel da...@davea.name
Cc: tutor@python.org
Date: Tuesday, February 25
On Wed, Feb 26, 2014 at 3:50 AM, Albert-Jan Roskam fo...@yahoo.com wrote:
On Tue, Feb 25, 2014 at 4:54 PM, Dave Angel da...@davea.name wrote:
CreateProcess has its own design bobbles as well. For
example, if you forget to put quotes around the program
name, it will happily try to add .exe to
On 26 February 2014 08:50, Albert-Jan Roskam fo...@yahoo.com wrote:
Yesterday evening (it was *late* so forgive me if I wrong) I realized that
part of my confusion was also caused by the fact that I ran my code in Idle.
If I called subprocess.call with a list argument, it returned code 0
- Original Message -
From: Danny Yoo d...@hashcollision.org
To: Peter Otten __pete...@web.de
Cc: Python Tutor Mailing List tutor@python.org
Sent: Monday, February 24, 2014 11:01 PM
Subject: Re: [Tutor] subprocess.call list vs. str argument
Last comment (apologies for being so
Albert-Jan Roskam fo...@yahoo.com Wrote in message:
- Original Message -
From: Danny Yoo d...@hashcollision.org
To: Peter Otten __pete...@web.de
Cc: Python Tutor Mailing List tutor@python.org
Sent: Monday, February 24, 2014 11:01 PM
Subject: Re: [Tutor] subprocess.call list vs
On Tue, Feb 25, 2014 at 2:52 PM, Albert-Jan Roskam fo...@yahoo.com wrote:
Here is why I used shell=True before. Is it related to the
file paths?
cmd = (r'sphinx-apidoc '
r'-f -F '
r'-H %(title)s '
r'-A %(author)s '
r'-V %(version)s '
See the comment about 'args' in:
http://docs.python.org/2/library/subprocess.html#frequently-used-arguments
which says:
args is required for all calls and should be a string, or a
sequence of program arguments. Providing a sequence of arguments is
generally preferred, as it allows the
eryksun eryk...@gmail.com Wrote in message:
FYI, in Windows the situation is different. CreateProcess takes a
string argument, so the setup code changes to the following:
It's fine to use a string for args in Windows, and you may need to if
the program parses the command line
On Tue, Feb 25, 2014 at 4:54 PM, Dave Angel da...@davea.name wrote:
CreateProcess has its own design bobbles as well. For example, if
you forget to put quotes around the program name, it will
happily try to add .exe to *multiple* places in the hopes that
one of them will work.
Adding a
Hi,
In the code below, cmd1 and cmd2 are equivalent, as in: .join(cmd1) == cmd2.
But the first example returns a code 2, whereas the second runs successfully.
What is the difference? I prefer using a list as it looks a little cleaner.
Btw, shell=True is needed here.
# Python 2.7.3 (default,
cmd1 = [r'sphinx-apidoc',
r'-f -F',
This part looks suspicious. Are you sure you don't mean:
'-f', '-F'
here? They need to be separate arguments.
Also, you mention:
Btw, shell=True is needed here.
Why do you need shell expansion on the arguments? This can be
dangerous
Albert-Jan Roskam wrote:
Hi,
In the code below, cmd1 and cmd2 are equivalent, as in: .join(cmd1) ==
cmd2. But the first example returns a code 2, whereas the second runs
successfully. What is the difference? I prefer using a list as it looks a
little cleaner. Btw, shell=True is needed
Peter Otten wrote:
r'-f -F',
r'-H', '%s' % title,
title becomes \title\, i. e. Python puts in an extra effort to have
the quotes survive the subsequent parsing process of the shell:
print subprocess.list2cmdline(['title'])
\title\
Forget that :(
Danny spotted the real problem.
There are a few issues there. I'd also recommend not trying to
shell-quote these manually,
# in the argument list of os.subprocess:
r'-H', '%s' % title,
r'-A', '%s' % author,
r'-V', '%s' % version,
Rather, just do the simpler thing:
r'-H', title,
r'-A', author,
Last comment (apologies for being so fragmented!). I don't know why
the literal strings there are raw there. Altogether, I'd expect:
#
cmd1 = ['sphinx-apidoc',
'-f',
'-F',
'-H', title,
'-A', author,
'-V', version,
16 matches
Mail list logo