从 php exec 获取 return 结果
Get and return result from php exec
嗨,我想 运行 外部 php 脚本,发送像字符串这样的参数并得到结果,数组结果
我的主管是:
exec("php' . 'test.php' ' $test, $retVal);
在测试中 php 我试图回应或其他东西但它不起作用
所以我想打电话给 php test.php 。并使用我发送的参数得到 true 或 false 的响应
那个脚本应该 运行 在 bacgrkound 中,所以它必须是 shel_exec 或 exec 但如果他接到 exec
的电话,它应该 return 字符串
试试下面的代码:
exec('php index2.php '.$start.' '.$end);
yourfile.php
<?php
$value = "a";
exec("php -f test.php $value", $output);
print_r($output);
$array = json_decode($output[0], true);
print($array["foo"]);
$value = "b";
exec("php -f test.php $value", $output2);
print_r($output2);
?>
test.php
<?php
if($argv[1] == "a"){
$array = array(
"foo" => "bar",
"bar" => "foo",
);
echo json_encode($array);
} else {
echo "it wasn't an a";
}
?>
要获得 "true" 或 "false" 如果 exec 成功:
exec("php -f test.php $value", $output, $return); /* print($return) */
$output 包含 php 脚本显示的所有内容,这就是为什么你应该使用 json 来显示你的对象,然后将其编码回他的状态。
嗨,我想 运行 外部 php 脚本,发送像字符串这样的参数并得到结果,数组结果
我的主管是:
exec("php' . 'test.php' ' $test, $retVal);
在测试中 php 我试图回应或其他东西但它不起作用
所以我想打电话给 php test.php 。并使用我发送的参数得到 true 或 false 的响应
那个脚本应该 运行 在 bacgrkound 中,所以它必须是 shel_exec 或 exec 但如果他接到 exec
的电话,它应该 return 字符串试试下面的代码:
exec('php index2.php '.$start.' '.$end);
yourfile.php
<?php
$value = "a";
exec("php -f test.php $value", $output);
print_r($output);
$array = json_decode($output[0], true);
print($array["foo"]);
$value = "b";
exec("php -f test.php $value", $output2);
print_r($output2);
?>
test.php
<?php
if($argv[1] == "a"){
$array = array(
"foo" => "bar",
"bar" => "foo",
);
echo json_encode($array);
} else {
echo "it wasn't an a";
}
?>
要获得 "true" 或 "false" 如果 exec 成功:
exec("php -f test.php $value", $output, $return); /* print($return) */
$output 包含 php 脚本显示的所有内容,这就是为什么你应该使用 json 来显示你的对象,然后将其编码回他的状态。