Trying to execute shell command in background using pythons commands module
>>>import commands
>>>output = commands.getstatusoutput("find / > tmp.txt &")
sh: Syntax error: ";" unexpected
Can anyone explain what is wrong with the syntax ? How should it be executed then ?
Tazim.
According to the getstatusoutput documentation,
commands.getstatusoutput(cmd)is executed asso your command is run as if it was
and the
;is not valid after the&in such a command.You should use the subprocess module to simulate the old-style
os.spawncommands.Try