Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29115
| References | <746448155.528147.1347550469072.JavaMail.root@sequans.com> <mailman.616.1347551196.27098.python-list@python.org> <a328f7cc-48e3-426d-bfd1-9c8893e1b701@googlegroups.com> |
|---|---|
| Date | 2012-09-13 22:24 -0700 |
| Subject | Re: subprocess call is not waiting. |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.667.1347600247.27098.python-list@python.org> (permalink) |
On Thu, Sep 13, 2012 at 11:36 AM, <paulstaten@gmail.com> wrote:
> Thanks, guys.
> MRAB-RedHat 6 64-bit, Python 2.6.5
In your Unix shell, what does the command:
type htar
output?
> JM-Here's the relevant stuff from my last try.
If you could give a complete, self-contained example, it would assist
us in troubleshooting your problem.
> I've also tried with subprocess.call. Just now I tried shell=True, but it made no difference.
It's possible that htar uses some trickery to determine whether it's
being invoked from a terminal or by another program, and changes its
behavior accordingly, although I could not find any evidence of that
based on scanning its manpage.
> sticking a print(out) in there just prints a blank line in between each iteration. It's not until the 5 trials are finished that I am told: download failed, etc.
>
> from os.path import exists
> from subprocess import call
> from subprocess import Popen
> from shlex import split
> from time import sleep
>
> while (exists(file)==0) and (nTries < 5):
`file` is the name of a built-in type in Python; it should therefore
not be used as a variable name.
Also, one would normally write that as:
while not exists(file) and nTries < 5:
> a = Popen(split('htar -xvf ' + htarArgs), stdout=PIPE, stderr=PIPE)
What's the value of `htarArgs`? (with any sensitive parts anonymized)
Also, you really shouldn't use shlex.split() at run-time like that.
Unless `htarArgs` is already quoted/escaped, you'll get bad results
for many inputs. Use shlex.split() once at the interactive interpreter
to figure out the general form of the tokenization, then use the
static result in your program as a template.
> (out,err) = a.communicate()
> if exists(file)==0:
> nTries += 1
> sleep(0.5)
>
> if exists(file)==0: # now that the file should be moved
> print('download failed: ' + file)
> return 1
>
> I've also tried using shell=True with popopen.
I presume you meant Popen.
Cheers,
Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: subprocess call is not waiting. MRAB <python@mrabarnett.plus.com> - 2012-09-13 16:46 +0100
Re: subprocess call is not waiting. paulstaten@gmail.com - 2012-09-13 11:36 -0700
Re: subprocess call is not waiting. Chris Rebert <clp2@rebertia.com> - 2012-09-13 22:24 -0700
Re: subprocess call is not waiting. paulstaten@gmail.com - 2012-09-13 11:36 -0700
csiph-web