468,758 Members | 2,074 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,758 developers. It's quick & easy.

regarding system function

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
Jul 19 '05 #1
1 1399
praba kar <pr*********@yahoo.co.in> writes:
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
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mosas | last post: by
reply views Thread by Paul Hsieh | last post: by
3 posts views Thread by Marcelo | last post: by
12 posts views Thread by sunil | last post: by
4 posts views Thread by Benny Van | last post: by
2 posts views Thread by somenath | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.