1

我在同一个目录中有两个文件。我想从命令行执行第一个,这将调用第二个。由于某种原因,这不起作用。我没有收到任何错误,也没有任何回应。

// test.php
<?php
    $value = 123;
    exec("php -f test1.php $value");
?>

// test1.php
<?php
    echo ">>>>>>>>".$argv[1]."<<<<<<<<";
?>
4

1 回答 1

3

您没有获取该命令的输出。这就是为什么尽管执行了命令你什么也看不到的原因。有几种方法可以做到这一点。这是最常见的:

// test.php
<?php
    $value = 123;
    // will output redirect directly to stdout
    passthru("php -f test1.php $value");

    // these functions return the outpout
    echo shell_exec("php -f test1.php $value");
    echo `php -f test1.php $value`;
    echo system("php -f test1.php $value");

    // get output and return var into variables
    exec("php -f test1.php $value", $output, $return);
    echo $output;
?>
于 2013-07-12T13:00:13.857 回答