[Twisted-Python] Problem with process ?

Andrew Bennetts andrew-twisted at puzzling.org
Tue Sep 14 08:31:36 EDT 2004

On Tue, Sep 14, 2004 at 01:58:37PM +0200, Philippe Bouige wrote:
>    But when i change
>    by :
>    return utils.getProcessOutput("ls",["-l *"])   
>    or :
>    return utils.getProcessOutput("ls",["-l -a"])
>    or :
>    return utils.getProcessOutput("ls",["-l ."])
>    and i have allways this error, but I don't undestand ??

It's because you need to pass the paramater list that's passed to exec(2),
not a command string that's passed to sh(1).

At the kernel (i.e. syscall) level, the exec syscall receives a list of
strings, where each argument in argv is a string, and can contain spaces or
* or anything character, except '\0'.

At the level you're probably used to, the shell, you just type "ls -ld *" or
whatever, and the shell expands and splits that up into the list of strings
for the exec syscall (in this example, something like ["ls", "-ld", "file1",
"file2", ...]).

If you want to do the shell's expansion and splitting of a commandline, just
explicitly invoke then shell:

    return utils.getProcessOutput('sh', ['-c "ls -l *"'])

(But beware passing user input directly into that; it's potentially a big
security hole that will allow running of arbitrary shell commands)


More information about the Twisted-Python mailing list