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.