[Tutor] os.system() problem
Aditya Lal
aditya.n.lal at gmail.com
Tue Feb 5 17:00:56 CET 2008
On 04/02/08 10:42 PM, "Eric Brunson" <brunson at brunson.com> wrote:
> dave selby wrote:
>> Hi all,
>>
>> I am not sure if this is a Python or bash issue :).
>>
>> In bash if I execute 'motion' with the following ...
>>
>> dave at dev-machine:~/.kde/share/apps/kmotion$ motion &> /dev/null &
>> [1] 10734
>> dave at dev-machine:~/.kde/share/apps/kmotion$
>>
>> I get what I expect, a background job, however if I execute it from
>> Python with an os.system ...
>>
>> os.system('motion &> /dev/null &')
>>
>
> This happens because &> and & are shell constructs, they are bash
> specific shell syntax for "redirect stderr and stdout" and "put this job
> in the background". But os.system simply calls the OS's "system(3)"
> call, which under linux calls "/bin/sh". If you read the docs for bash,
> calling it as "sh" results in POSIX compliance mode and falls back to
> Bourne shell's less rich syntax, so it doesn't understand the "&>"
> construct. If I had to guess at the parsing, I imagine it runs the
> "motion &" as one process in the background, then "> /dev/null &" as a
> second.
>
> Long story short, look at this page:
> http://docs.python.org/lib/node537.html
>
>> I get tons of output to the BASH shell ...
>>
>> [0] Processing thread 0 - config file /etc/motion/motion.conf
>> [0] Processing config file /etc/motion/motion.1.conf
>> [0] Processing config file /etc/motion/motion.2.conf
>> [1] Thread is from /etc/motion/motion.1.conf
>> [2] Thread is from /etc/motion/motion.2.conf
>> [1] Thread started
>> [2] Thread started
>> [1] File of type 2 saved to: /var/lib/motion/20080203/01/tmp/175253.jpg
>> ...etc ...
>>
>> I just can't work out why this is happening & how to stop it ?. Any ideas ?
>>
>> Cheers
>>
>> Dave
>>
>>
Try os.system('bash motion &> /dev/null &')
More information about the Tutor
mailing list