Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46145
| X-Received | by 10.224.3.131 with SMTP id 3mr4627924qan.5.1369612737911; Sun, 26 May 2013 16:58:57 -0700 (PDT) |
|---|---|
| X-Received | by 10.49.97.130 with SMTP id ea2mr2158558qeb.13.1369612737896; Sun, 26 May 2013 16:58:57 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!ch1no1275845qab.0!news-out.google.com!y6ni51517qax.0!nntp.google.com!ch1no1275837qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Sun, 26 May 2013 16:58:57 -0700 (PDT) |
| In-Reply-To | <mailman.2202.1369602328.3114.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=86.30.140.68; posting-account=Y18FNAoAAAAH6J_Od-2qLV1CDigBCPRj |
| NNTP-Posting-Host | 86.30.140.68 |
| References | <062f557e-8e1a-4efb-9178-7d685b47a834@googlegroups.com> <mailman.2202.1369602328.3114.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <08aa32b7-0fb7-4665-83fa-5cc7ec36f898@googlegroups.com> (permalink) |
| Subject | Re: Piping processes works with 'shell = True' but not otherwise. |
| From | Luca Cerone <luca.cerone@gmail.com> |
| Injection-Date | Sun, 26 May 2013 23:58:57 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Xref | csiph.com comp.lang.python:46145 |
Show key headers only | View raw
> Could you provide the *actual* commands you're using, rather than the generic "program1" and "program2" placeholders? It's *very* common for people to get the tokenization of a command line wrong (see the Note box in http://docs.python.org/2/library/subprocess.html#subprocess.Popen for some relevant advice). > Hi Chris, first of all thanks for the help. Unfortunately I can't provide the actual commands because are tools that are not publicly available. I think I get the tokenization right, though.. the problem is not that the programs don't run.. it is just that sometimes I get that error.. Just to be clear I run the process like: p = subprocess.Popen(['program1','--opt1','val1',...'--optn','valn'], ... the rest) which I think is the right way to pass arguments (it works fine for other commands).. > > Could you provide the full & complete error message and exception traceback? > yes, as soon as I get to my work laptop.. > > One obvious difference between the 2 approaches is that the shell doesn't redirect the stderr streams of the programs, whereas you /are/ redirecting the stderrs to stdout in the non-shell version of your code. But this is unlikely to be causing the error you're currently seeing. > > > You may also want to provide /dev/null as p1's stdin, out of an abundance of caution. > I tried to redirect the output to /dev/null using the Popen argument: 'stdin = os.path.devnull' (having imported os of course).. But this seemed to cause even more troubles... > Lastly, you may want to consider using a wrapper library such as http://plumbum.readthedocs.org/en/latest/ , which makes it easier to do pipelining and other such "fancy" things with subprocesses, while still avoiding the many perils of the shell. > > Thanks, I didn't know this library, I'll give it a try. Though I forgot to mention that I was using the subprocess module, because I want the code to be portable (even though for now if it works in Unix platform is OK). Thanks a lot for your help, Cheers, Luca
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Piping processes works with 'shell = True' but not otherwise. Luca Cerone <luca.cerone@gmail.com> - 2013-05-24 07:04 -0700
Re: Piping processes works with 'shell = True' but not otherwise. Luca Cerone <luca.cerone@gmail.com> - 2013-05-26 03:31 -0700
Re: Piping processes works with 'shell = True' but not otherwise. Chris Rebert <clp2@rebertia.com> - 2013-05-26 14:05 -0700
Re: Piping processes works with 'shell = True' but not otherwise. Luca Cerone <luca.cerone@gmail.com> - 2013-05-26 16:58 -0700
RE: Piping processes works with 'shell = True' but not otherwise. Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-27 03:14 +0300
Re: Piping processes works with 'shell = True' but not otherwise. Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-05-29 19:39 +0200
RE: Piping processes works with 'shell = True' but not otherwise. Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-29 22:31 +0300
Re: Piping processes works with 'shell = True' but not otherwise. Cameron Simpson <cs@zip.com.au> - 2013-05-30 08:18 +1000
Re: Piping processes works with 'shell = True' but not otherwise. Chris Angelico <rosuav@gmail.com> - 2013-05-27 18:28 +1000
Re: Piping processes works with 'shell = True' but not otherwise. Luca Cerone <luca.cerone@gmail.com> - 2013-05-27 04:33 -0700
Re: Piping processes works with 'shell = True' but not otherwise. Chris Rebert <clp2@rebertia.com> - 2013-05-29 10:17 -0700
Re: Piping processes works with 'shell = True' but not otherwise. Luca Cerone <luca.cerone@gmail.com> - 2013-05-31 02:28 -0700
Re: Piping processes works with 'shell = True' but not otherwise. Peter Otten <__peter__@web.de> - 2013-05-31 11:52 +0200
csiph-web