[Python-Dev] Re: subprocess - updated popen5 module
Nick Coghlan
ncoghlan at email.com
Sat Oct 9 18:24:00 CEST 2004
Quoting Peter Astrand <astrand at lysator.liu.se>:
> >Your examples don't work with call either, right?
>
> They work with call if you use a string argument. That's the core of the
> problem: The callv function doesn't support passing a string-type args
> argument to the Popen constructor.
>
>
> >Their
> > call() equivalents:
> >
> > subprocess.call(["somewindowsprog.exe some strange command line"])
> > subprocess.call(["somewindowsprog.exe", "some", "strange", "command",
> "line"])
> >
> > are just as broken, no?
>
> Yes. You'll need to do:
>
> subprocess.call("somewindowsprog.exe some strange command line")
Given that call is only a shortcut function, wouldn't the following suffice?:
def call(*args, **kwds):
if len(args) <= 1:
return Popen(*args, **kwds)
else:
return Popen(args, **kwds)
With that implementation, a single string, a list, a sequence of strings and
Popen keywords only would all work as arguments to call. That is:
call("ls -l") -> Popen("ls -l")
call("ls", "-l") -> Popen(["ls", "-l"])
call(["ls", "-l"]) -> Popen(["ls", "-l"])
call(args="ls -l") -> Popen(args="ls -l")
All it would mean is that if you want to use the optional arguments to Popen,
you either don't use call, or you use keywords.
Cheers,
Nick.
--
Nick Coghlan
Brisbane, Australia
More information about the Python-Dev
mailing list