Using "subprocess" without lists. . .?

Steven Bethard steven.bethard at gmail.com
Sun May 13 13:05:41 EDT 2007


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



More information about the Python-list mailing list