Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Need help with os.system in linux

Reply
Thread Tools

Need help with os.system in linux

 
 
akshay bhat
Guest
Posts: n/a
 
      01-17-2009
Hello
i am calling a program using os.system in python on Linux.
However in i found that program being executed and soon returned 256.
but when i ran it using terminal i got proper results.
Now in case of windows, python waits till the process is finished,
Can you please tell me how to implement this in linux?
 
Reply With Quote
 
 
 
 
excord80
Guest
Posts: n/a
 
      01-17-2009
On Jan 16, 7:05*pm, akshay bhat <(E-Mail Removed)> wrote:
> Hello
> i am calling a program using os.system in python on Linux.
> However in i found that program being executed and soon returned 256.
> but when i ran it using terminal i got proper results.
> Now in case of windows, python waits till the process is finished,
> Can you please tell me how to implement this in linux?


Maybe it runs faster in GNU/Linux?

Either way, you probably want to post some minimal example code if you
would like more help on this.
 
Reply With Quote
 
 
 
 
Thomas Bellman
Guest
Posts: n/a
 
      01-17-2009
akshay bhat <(E-Mail Removed)> writes:

> i am calling a program using os.system in python on Linux.
> However in i found that program being executed and soon returned 256.
> but when i ran it using terminal i got proper results.


Under Linux (but unfortunately not generally under Unix), you can
interpret return code from os.system() using os.WIFSIGNALED() or
os.WIFEXITED(), and os.WEXITSTATUS() or os.WTERMSIG(). Something
like this:

status = os.system(commandline)
if os.WIFSIGNALED(status):
print "Command was killed by signal", os.WTERMSIG(status)
else:
print "Command exited with return status", os.WEXITSTATUS(status)

(os.WIFSIGNALED() and os.WIFEXITED() are each others inverses,
for this use case. In the above code, I could have used 'not
os.WIFEXITED(status)' instead of 'os.WIFSIGNALED(status)' without
changing its meaning.)

If you do that for your program, you will see that the program
you call are exiting with return status 1 (that's what a return
value of 256 from os.system() happens to mean), i.e it is calling
exit() with 1 as argument.

*Why* the program you are calling does that, is impossible to
tell from the information you have given us. You haven't even
told us what command line you are passing to os.system(), so if
you need more help, you must tell us more.


May I also suggest that you use the subprocess module instead of
os.system(). The subprocess module is a newer and better interface
for running external commands. For example, you can avoid having
to deal with quoting shell metacharacters, and interpreting the
return values are easier.


--
Thomas Bellman, Lysator Computer Club, Linköping University, Sweden
"Life IS pain, highness. Anyone who tells ! bellman @ lysator.liu.se
differently is selling something." ! Make Love -- Nicht Wahr!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Is Netscape Leaving Firefox Behind on GNU/Linux? THE LINUX PROPAGANDA MACHINE CONTINUES. FIREFOX IGNORING LINUX............. traci.manicotti@gmail.com Computer Support 2 10-20-2007 02:12 PM
re_---need help Network Adapters!!!! NEED HELP!!!! hedayatniac@gmail.com Computer Support 4 08-13-2006 01:03 AM
Linux... yeah linux.. Linux Have a nice cup of pee NZ Computing 19 04-17-2006 10:16 AM
Need help with PCI aironet 340 card under linux & bsd... itsvincer@gmail.com Cisco 4 11-03-2005 07:06 AM
Need help diagnosing a JVM crash on Linux Tony Java 0 10-15-2004 10:54 PM



Advertisments