Python-os. Command Execution
ALAN GAULD
alan.gauld at btinternet.com
Sat Feb 19 05:04:02 EST 2011
> when user click install, It will start one GUI installation script and
> exit my application
>
> This my task.. The problem was the installation script started but
> control will be transfered to
>
> other window ... when installation finished the GUI application will be
>closed..
>
> code:
>
> os.system("ls -l") & root.destroy
>
First question is, why are you using the bitwise and operator to manage
execution status. This is Python not C. Use clear logic that erflects
what you are trying to do.( Especially if you only post code fragments.)
if os.system('ls -l') != 0 : root.destroy()
Is much more obvious in intent.
> when execute a command "ls -l " and application will be closed
Only if os.system returns an error code
> os.system("top") & root.destroy
>
> Control will the transferred to the other-window, "top" closed means
> application will be closed.. plz..help me..
I have no idea what other window you are referring to. Is it the
OS console that top runs in? Have you checked the return code
of os.system to see if it returns cleanly (ie a 0) or if it returns an error?
You might find it better to use the subprocess module instead of
os.system. There is more flexibilityy and control available there.
> I checked also the command as background process.. like os.system("top
> &") & root.destroy
And what happened?
We need a bit more context and you need to do a bity more debugging.
Starting with getting rid of the bitwise and "trick" from C. All it does
here is make it hard to understand whats happening.
HTH,
Alan G.
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Python-list
mailing list