Re: [Tutor] subprocess.call list vs. str argument

2014-02-28 Thread Albert-Jan Roskam
] 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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-26 Thread Albert-Jan Roskam
? ~~ 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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-26 Thread eryksun
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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-26 Thread Oscar Benjamin
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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-25 Thread Albert-Jan Roskam
- 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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-25 Thread Dave Angel
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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-25 Thread eryksun
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 '

Re: [Tutor] subprocess.call list vs. str argument

2014-02-25 Thread Danny Yoo
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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-25 Thread Dave Angel
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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-25 Thread eryksun
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

[Tutor] subprocess.call list vs. str argument

2014-02-24 Thread Albert-Jan Roskam
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,

Re: [Tutor] subprocess.call list vs. str argument

2014-02-24 Thread Danny Yoo
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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-24 Thread Peter Otten
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

Re: [Tutor] subprocess.call list vs. str argument

2014-02-24 Thread Peter Otten
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.

Re: [Tutor] subprocess.call list vs. str argument

2014-02-24 Thread Danny Yoo
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,

Re: [Tutor] subprocess.call list vs. str argument

2014-02-24 Thread Danny Yoo
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,