PHP proc_open won't work - gives me "Missing handle qualifier in array"
Asked Answered
M

1

6

Warning: proc_open(): Missing handle qualifier in array in C:\...\updatedots.php on line 102

I'm trying to open notepad the close it after 2 seconds. This is my code:

$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"]);

Any idea what this error means and what causes it?

Maghutte answered 18/5, 2011 at 13:55 Comment(4)
Then what Stephan said. Regardless, my comment was an attempt to prompt you into providing more explicit information in your questions in future.Gaut
Just to clarify, since my code only contains one instance of proc_open I assumed it would be obvious that the error message is referring to it. That's how I thought of it anywayMaghutte
What I was trying to get at is that we prefer you post minimal testcases, and the error messages should come from those testcases.Gaut
The error message clearly doesn't come from the posted code, as the posted code doesn't contain 102 lines ;)Gaut
R
11

It is not 0 => array("pipe" => "r") but 0 => array("pipe", "r") ^^

Additionally, when giving a filename you need to specify the mode to use. This works on my machine:

$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"]); 
Republicanism answered 18/5, 2011 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.