2017-09-26 14 views
0

これは、このサイトで何度も尋ねられていますが、私はまだ何か問題を抱えています。青色 須藤のPythonのtest1.pyphpからpythonへの値渡し

test1.py

import sys 
 
who = sys.argv[1] 
 
print sys.argv[1] 
 
print who

出力:

PHPから ブルーブルー

のbashから

パイソン からの出力で

$ledcolor = "0,255,0"; 
 

 

 
$result = exec("sudo python test1.py blue"); 
 
$result = exec("sudo python test1.py" . $ledcolor); 
 
$result = exec('sudo python test1.py' . $ledcolor); 
 
$result = exec('sudo python test1.py blue');

すべての結果は、私も同じ(NO)の結果をPHPにもしくはshell_execを試みました。

$result = exec("sudo python test1.py blue" . $ledcolor); 
 
    echo "\n"; 
 
    print $result;
PHP出力= blue0,255,0

私が間違って何をやっていますか? PHPで

+2

'$ result'を印刷しましたか? –

+0

echos変数のみがコードと結果でメインポストを更新しました – jointtech

答えて

0

exec関数は、参照によって渡されたパラメータを介して、その全出力を渡し:

$out = ''; 
$cmd = exec('/bin/somecommand some parameters', $out); 
echo $out; 

$cmdは、execコールはなく、出力のリターン・ステータスを保持しています。

参考:http://php.net/manual/en/function.exec.php

0

あなたはshell_exec代わりのexec、または ``を使用することができます。

$result = `sudo python test1.py blue`; 
関連する問題