regarding system function

P

praba kar

Dear All,

In Php If I send a command to system function
then It will return 1 on success and 0 on failure. So
based upon that value I can to further work.

But In Python If I send a command to system
function then It will return 0 only for both
conditions(success and failure). So What I need
to do for this. I want the result like php system
function.


regards
Prabahar


________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
 
M

Mike Meyer

praba kar said:
Dear All,

In Php If I send a command to system function
then It will return 1 on success and 0 on failure. So
based upon that value I can to further work.

But In Python If I send a command to system
function then It will return 0 only for both
conditions(success and failure). So What I need
to do for this. I want the result like php system
function.

You don't say what platform you're on, but from your description of
the problem, it's not Unix:

py> os.system("grep foo /dev/null")
256
py> os.system("grep foo /no_such_file")
grep: /no_such_file: No such file or directory
512

os.system is a simple wrapper around the C system() function. It's
return value is the same as that function. On unix, that's the 1/0 you
want in the upper byte, and status information in the lower byte - so
you divide by 256. I have no idea what Windows does in this case.

I'd recommend using the subprocess routines instead of os.system. They
are much more powerful/flexible than os.system.

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top