468,316 Members | 1,522 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

Using "subprocess" without lists. . .?

Hi All,

I've recently seen the "subprocess" module and am rather confused by
it's requirements. Is it not possible to execute an entire string
without having to break them up into a list of arguments? For
instance, I'd much rather do the following:
subprocess.call("ls -al | grep -i test")
.. . .than to have to:
list = ["ls", "-a", "-l" ] . . . . . . and so on and so forth.
subprocess.call(list. . .)
What is the best way to go about executing a massively complex single
line command?
Thanks,
Michael
May 13 '07 #1
3 1108
Michael Williams wrote:
Hi All,

I've recently seen the "subprocess" module and am rather confused by
it's requirements. Is it not possible to execute an entire string
without having to break them up into a list of arguments? For instance,
I'd much rather do the following:
subprocess.call("ls -al | grep -i test")
. . .than to have to:
list = ["ls", "-a", "-l" ] . . . . . . and so on and so forth.
subprocess.call(list. . .)
What is the best way to go about executing a massively complex single
line command?

You could always call "ls -al | grep -i test".split().

STeVe
May 13 '07 #2
Michael Williams wrote:
I've recently seen the "subprocess" module and am rather confused by
it's requirements. Is it not possible to execute an entire string
without having to break them up into a list of arguments? For
instance, I'd much rather do the following:
subprocess.call("ls -al | grep -i test")
Try

subprocess.call("ls -al | grep -i test", shell=True)
>

. . .than to have to:
list = ["ls", "-a", "-l" ] . . . . . . and so on and so forth.
subprocess.call(list. . .)
which avoids a lot of problems with shell quoting.

Peter
May 13 '07 #3
Steven Bethard wrote:
You could always call "ls -al | grep -i test".split().
Or better, shlex.split().

Peter
May 13 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Didier C | last post: by
3 posts views Thread by Darren Dale | last post: by
3 posts views Thread by Alex Kachanov | last post: by
3 posts views Thread by Tom Plunket | last post: by
1 post views Thread by Jim | last post: by
5 posts views Thread by Grant Edwards | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.