PHP proc_open将无法正常工作 - 给我“数组中缺少句柄限定符”

时间:2011-05-18 13:55:36

标签: php windows xampp proc-open

  

警告:proc_open():在第102行的C:\ ... \ updatedots.php中缺少数组中的句柄限定符

我试图打开记事本,关闭它2秒后。这是我的代码:

$descriptorspec = array(
    0 => array("pipe" => "r"),
    1 => array("pipe" => "w"),
    2 => array("file" => "logs/errors.txt")
);

// Create child and start process
$child = array("process" => null, "pipes" => array());
$child["process"] = proc_open("notepad.exe > nul 2>&1", $descriptorspec, $child["pipes"]);

知道这个错误意味着什么,是什么原因造成的?

1 个答案:

答案 0 :(得分:10)

不是0 => array("pipe" => "r")而是0 => array("pipe", "r") ^^

此外,在提供文件名时,您需要指定要使用的模式。这适用于我的机器:

$descriptorspec = array(
    0 => array("pipe", "r"),
    1 => array("pipe", "w"),
    2 => array("file", "logs/errors.txt", "a") ); 
// Create child and start process 
$child = array("process" => null, "pipes" => null); 
$child["process"] = proc_open("notepad.exe > nul 2>&1", $descriptorspec, $child["pipes"]);