note 128294 added to function.exec

From: Date: Mon, 06 Mar 2023 14:37:54 +0000
Subject: note 128294 added to function.exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-220251@lists.php.net to get a copy of this message
<this note copied from system page> This is for WINDOWS users. I am running apache and I have been trying for hours now to capture the output of a command. I'd tried everything that is written here and then continued searching online with no luck at all. The output of the command was never captured. All I got was an empty array. Finally, I found a comment in a blog by a certain amazing guy that solved my problems. Adding the string ' 2>&1' to the command name finally returned the output!! This works in exec() as well as system() in PHP since it uses stream redirection to redirect the output to the correct place! <?php exec("yourCommandName 2>&1", $output); var_dump($output); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 212.90.59.36) ---- Manual Page -- https://php.net/manual/en/function.exec.php Edit -- https://main.php.net/note/edit/128294 Del: integrated -- https://main.php.net/note/delete/128294/integrated Del: useless -- https://main.php.net/note/delete/128294/useless Del: bad code -- https://main.php.net/note/delete/128294/bad+code Del: spam -- https://main.php.net/note/delete/128294/spam Del: non-english -- https://main.php.net/note/delete/128294/non-english Del: in docs -- https://main.php.net/note/delete/128294/in+docs Del: other reasons-- https://main.php.net/note/delete/128294 Reject -- https://main.php.net/note/reject/128294 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220251) next »