Call Python From PHP And Get Return Code

后端 未结 2 1533
失恋的感觉
失恋的感觉 2020-11-30 08:24

I am calling a python script from PHP.

The python program has to return some value according to the arguments passed to it.

Here is a sample python program,

相关标签:
2条回答
  • 2020-11-30 08:30

    That is correct use of exit(). See also: http://docs.python.org/library/sys.html

    0 讨论(0)
  • 2020-11-30 08:51

    In PHP, you can execute a command and obtain the return code using exec.

    The manual for exec says the third parameter is a variable in which the return code will be stored, for example

    exec('python blibble.py', $output, $ret_code);
    

    $ret_code will be the shell return code, and $output is an array of the lines of text printed to std. output.

    This does appear to be an appropriate use for a return code from what you described, i.e. 0 indicating success, and >0 being codes for various types of errors.

    0 讨论(0)
提交回复
热议问题