小编sea*_*boy的帖子

从PHP调用Python并获取返回代码

我从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 …
Run Code Online (Sandbox Code Playgroud)

php python

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

php ×1

python ×1