简体   繁体   English

Python:从python脚本调用php脚本时,找不到PHP致命错误类

[英]Python: PHP fatal Error Class not found when php script called from python script

I am trying to call a php script from python script using subprocess : 我试图使用subprocess从python脚本调用php脚本:

cmd1 = 'php -f ' + path + '/src/MarketplaceWebService/Samples/ReviseItem.php %s %s' % (sku,qty)
print cmd1
args1 = shlex.split(cmd1)
p=subprocess.Popen(args1)
p.wait()

But i am getting the followwing error: 但是我遇到了跟​​随错误:

PHP Fatal error: Class 'MarketplaceWebService_Client' not found in /home/nish/stuff/repos/new/voylla_staging_changes/voylla_scripts/amazon/src/MarketplaceWebService/Samples/ReviseItem.php on line 70 PHP致命错误:在第70行的/home/nish/stuff/repos/new/voylla_staging_changes/voylla_scripts/amazon/src/MarketplaceWebService/Samples/ReviseItem.php中找不到类“ MarketplaceWebService_Client”

When I run the same php script via command line using php -f ReviseItem.php , it works fine without any errors. 当我使用php -f ReviseItem.php通过命令行运行相同的php脚本时,它工作正常,没有任何错误。 How can i fix this error. 我该如何解决此错误。

the include() or require() calls in your php scripts are using relative file paths, which are themselves relatives to the directory you actually are in when you run the command. php脚本中的include()require()调用使用的是相对文件路径,它们本身就是您在运行命令时实际所在目录的相对路径。

You can assert this with a echo getcwd(); 您可以使用echo getcwd();来断言echo getcwd(); call at the beginning of your php script, for example. 例如,在php脚本的开头调用。

So, you have to either modify your python code to cd to the right dir prior to running the command (easier), or modify your php scripts to use absolute paths for inclusion (not the best way to go since your scripts would be tied to a specific directory on the system). 因此,您必须在运行命令之前(轻松)将python代码修改为cd到正确的目录,或者修改php脚本以使用绝对路径进行包含(这不是最好的方法,因为您的脚本将被绑定到系统上的特定目录)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM