note 125899 added to function.shell-exec

From: Date: Thu, 11 Mar 2021 06:01:36 +0000
Subject: note 125899 added to function.shell-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-219198@lists.php.net to get a copy of this message
An important thing to consider is in some cases, like on MacOS, using "2>&1" to properly output string from exec() works well when you wrap the command in parenthesis. For example: WITH PARENTHESIS AROUND CMD $cmd = "(mysqldump -h l ocalhost -u root -ppassword --databases login_practice_db > /Users/username/Desktop/testDB.sql) 2>&1"; $sys = shell_exec($cmd ); //Works and produces an error (localhost is poorly spaced on purpose) WITHOUT PARENTHESIS AROUND CMD $cmd = "mysqldump -h l ocalhost -u root -ppassword --databases login_practice_db > /Users/username/Desktop/testDB.sql 2>&1"; $sys = shell_exec($cmd ); //Does nothing and goes blank as if the result were error free. Empty string. It's interesting how shell command execution can get down to how nuanced one might need to be with string parsing. ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.246 (proxied: 2603:8000:aa00:b62c:2d55:fa80:72fa:3b6) ---- Manual Page -- http://php.net/manual/en/function.shell-exec.php Edit -- https://master.php.net/note/edit/125899 Del: integrated -- https://master.php.net/note/delete/125899/integrated Del: useless -- https://master.php.net/note/delete/125899/useless Del: bad code -- https://master.php.net/note/delete/125899/bad+code Del: spam -- https://master.php.net/note/delete/125899/spam Del: non-english -- https://master.php.net/note/delete/125899/non-english Del: in docs -- https://master.php.net/note/delete/125899/in+docs Del: other reasons-- https://master.php.net/note/delete/125899 Reject -- https://master.php.net/note/reject/125899 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#219198) next »