呼叫的結果我得到了這個時髦的Python代碼:蟒蛇2.6.5,並得到一個PHP應用程序
import subprocess
value = subprocess.Popen(["php","./php/php_runner.php"],stdout=subprocess.PIPE);
的問題是,我不知道如何檢查php_runner,好,跑了。目前,它具有以下幾個突出部分:
if (count($argv) != 4){
die("four arguments are needed\n");
}
和
$returnValue = call_to_another_php_class();
return $returnValue;
所以,我想是這樣的:
我如何獲得的返回值,不管它可能是,使用python?你可能會告訴我在答案中使用「PIPE」,但是(對我來說,不可理解的)python文檔(http://docs.python.org/library/subprocess.html)指出:
不要在此函數中使用stdout = PIPE或stderr = PIPE。由於在當前進程中沒有讀取管道,如果子進程產生足夠的輸出到管道來填充OS管道緩衝區,可能會阻塞子進程。 那麼我該怎麼用呢,因爲雖然我真的不知道他們在吠叫什麼,但我坐起來,注意到灰色框中的筆記。可惜他們沒有詳細說明我打算做什麼 - 但是,那麼我該怎麼做?
- 了「的returnValue」我的PHP代碼的回報,是是什麼蟒蛇會皮卡從函數的返回值?如果不是,我該如何返回該值?
乾杯!
UPDATE
由於給定的答案,這是我所做的更改:
- 編輯
/etc/php5/cli/conf.d/mcrypt.ini
(實際上,這僅僅是對Ubuntu 10.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()命令對我來說沒有那麼做。
改變蟒改爲:
value = subprocess.Popen(["php","./php/php_runner.php"],stdout=subprocess.PIPE, stderr=subprocess.PIPE); print value.communicate();
是的,現實的是,我會做一個如果上value.communicate()[1],becase的是其中錯誤。
$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); }
booyah!
感謝您的支持!我早些時候看過溝通,但沒有用PIPE的東西來設置它,所以我認爲它沒有像我想的那樣工作! – bharal 2012-01-29 22:11:20