Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用>/dev/null将不明确的数字输出到控制台_Php_Bash_Command Line_Terminal - Fatal编程技术网

Php 使用>/dev/null将不明确的数字输出到控制台

Php 使用>/dev/null将不明确的数字输出到控制台,php,bash,command-line,terminal,Php,Bash,Command Line,Terminal,因此,我需要通过命令行运行后台进程(使用exec),同时将参数传递给执行的PHP脚本 在继续之前,我将展示我的脚本,以便更好地了解正在发生的事情: var_dump($argv); exit; 要获得要传递的参数很简单,只需: $ php -q test.php foo bar 正如预期的那样,这将产生: array(2){ [0] => string(11) "test.php" [1] => string(3) "foo" [2] => stri

因此,我需要通过命令行运行后台进程(使用
exec
),同时将参数传递给执行的PHP脚本

在继续之前,我将展示我的脚本,以便更好地了解正在发生的事情:

var_dump($argv);
exit;
要获得要传递的参数很简单,只需:

$ php -q test.php foo bar
正如预期的那样,这将产生:

array(2){
    [0] => string(11) "test.php"
    [1] => string(3) "foo"
    [2] => string(3) "bar"
}
但是,为了异步运行脚本,我需要以下命令:

$ php -q test.php foo bar >/dev/null 2>/dev/null &
但出于某种原因,每次我执行命令时,它都会输出一个与此类似的任意数字:

[1] 79401
我一直在四处寻找解决办法,但在手头的事情上找不到任何东西


非常感谢您的帮助。

正如danlor所说,这是PHP脚本的进程id。 在命令末尾使用“&”意味着shell应该在后台运行该命令,因此shell会告诉您进程的PID。
您还可以通过使用“>/dev/null”和“2>/dev/null”抑制对stdout和stderr的任何输出。

正如danlor所述,它是PHP脚本的进程id。 在命令末尾使用“&”意味着shell应该在后台运行该命令,因此shell会告诉您进程的PID。
您还可以通过使用“>/dev/null”和“2>/dev/null”抑制对stdout和stderr的任何输出。

您可以将命令发送到后台,然后将输出发送到/dev/null


/bin/bash-c“php-q test.php foo bar&“2>&1>/dev/null

您可以将命令发送到后台,然后将输出发送到/dev/null


/bin/bash-c“php-q test.php foo bar&“2>&1>/dev/null

这是要发送到后台的进程的PID,不是任意数字。@danlor ohhh这很有意义。但是为什么它会输出与实际PHP脚本所期望的相反的结果呢?它会同时输出作业ID和PID,并输出到
stdout
stderr
,因为它们仍然连接到父shell。但是,请注意,
stdin
是分离的。由于您已将输出(stdout和stderr)重定向到
/dev/null
,因此它只会显示作业ID和PID。这是您发送到后台的进程的PID,而不是任意数字。@danlor ohh这很有意义。但是为什么它会输出与实际PHP脚本所期望的相反的结果呢?它会同时输出作业ID和PID,并输出到
stdout
stderr
,因为它们仍然连接到父shell。但是,请注意,
stdin
是分离的。由于您已将输出(stdout和stderr)重定向到
/dev/null
,因此它只会显示作业ID和PID。