【发布时间】:2010-04-28 02:59:52
【问题描述】:
我正在从 PHP 调用 python 脚本。
python 程序必须根据传递给它的参数返回一些值。
这是一个示例 python 程序,它将让您对我目前正在做的事情有一个基本的了解:
#!/usr/bin/python
import sys
#get the arguments passed
argList = sys.argv
#Not enough arguments. Exit with a value of 1.
if len(argList) < 3:
#Return with a value of 1.
sys.exit(1)
arg1 = argList[1]
arg2 = argList[2]
#Check arguments. Exit with the appropriate value.
if len(arg1) > 255:
#Exit with a value of 4.
sys.exit(4)
if len(arg2) < 2:
#Exit with a value of 8.
sys.exit(8)
#Do further coding using the arguments------
#If program works successfully, exit with a value of 0
从上面的代码可以看出,我的基本目标是
- 让 python 程序根据参数返回一些值(0、1、4、8 等)。
- 然后调用 PHP 程序来访问这些返回值并执行相应的操作。
目前我为此使用了“sys.exit(n)”。
我是在使用 sys.exit,还是我需要使用其他东西?
PHP 中还有什么方法可以让我从 python 访问返回码?
抱歉这个问题太长了,但希望它能帮助你理解我的困境
非常感谢
【问题讨论】: