php调用某应用程序,Python2.6.5,并获取对php应用程序的调用结果

我有一个时髦的python代码:import subprocess

value = subprocess.Popen(["php","./php/php_runner.php"],stdout=subprocess.PIPE);

问题是,我不知道如何检查php运行程序是否运行。目前,它有以下突出部分:

^{pr2}$

以及$returnValue = call_to_another_php_class();

return $returnValue;

所以我想要的是:如何使用python获得返回值(不管是什么)?

您可能会告诉我在答案中使用“PIPE”,但是(对我来说,无法理解的)python文档(http://docs.python.org/library/subprocess.html)国家:Do not use stdout=PIPE or stderr=PIPE with this function. As the pipes are not being read in >the current process, the child process may block if it generates enough output to a pipe to fill up >the OS pipe buffer.

So what do i use then, because while I don't really know what they're barking on about, i sit up and take note about notes in grey boxes. Pity they didn't spell out what i'm meant to do - but, well, what am i meant to do?

我的php代码返回的“returnValue”是python将从函数中获取的返回值?如果没有,如何返回该值?在

干杯!在

更新

多亏了给出的答案,以下是我所做的改变:编辑/etc/php5/cli/conf.d/mcrypt.ini(实际上,这只是对ubuntu10.04的一个更改,我将第一行改为以;而不是#开头。这就阻止了一个烦人的“我们不喜欢”错误不断出现)

在我的php中,我将代码改为:if (count($argv) != 4){

fwrite(STDERR, "four arguments are needed\n");

exit(1); // A response code other than 0 is a failure

}

这将把我的错误值作为一个错误。die()命令对我没用。

将python改为:value = subprocess.Popen(["php","./php/php_runner.php"],stdout=subprocess.PIPE,

stderr=subprocess.PIPE);

print value.communicate();

是的,事实上,我会做一个假设价值观。沟通()[1],因为错误就在这里。

$returnValue = call_to_another_php_class();

if ($returnValue == 1){ //hah, php has a good return value as 1.

//no problem

} else {

fwrite(STDERR,get_error_from_php_class());

exit(1);

}

布耶!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值