How can I use php exec to execute nodejs files? The following execution fails. {code ...} if only exec (& quot; node-v $ serverPath & quot;, $ info, $ val); is used, the version number can be output and the execution is successful. Thank you for your answers. How can I use php exec to execute nodejs files? The following execution fails.
public function execTask ($dirPath) { $serverPath = self::$serverPath; exec("node httpd.js $serverPath",$info, $val); var_dump($info); echo "$val"; }
If onlyexec("node -v $serverPath",$info, $val);
But the version number can be output and the execution is successful. Thank you for your answers.
Reply content:
How can I use php exec to execute nodejs files? The following execution fails.
public function execTask ($dirPath) { $serverPath = self::$serverPath; exec("node httpd.js $serverPath",$info, $val); var_dump($info); echo "$val"; }
If onlyexec("node -v $serverPath",$info, $val);
But the version number can be output and the execution is successful. Thank you for your answers.
You can try shell_exec.
I also have similar usage, so in addition to reading messages, there are also functions that can be executed directly in the background, all implemented through processes.
/*** The returned Chinese text is GB2312 encoded in windows and needs to be manually changed to UTF8 * iconv ("GB2312", "UTF-8", $ read ); * @ param $ cmd * @ return array */public function execFront ($ cmd) {$ response = array (); $ handle = popen ("$ cmd 2> & 1 ", 'R'); while ($ read = fread ($ handle, 20096) {if (! Mb_detect_encoding ($ read, 'utf-8', true) iconv ("GB2312", "UTF-8", $ read); $ response [] = trim ($ read );} pclose ($ handle); flush (); return $ response;}/*** @ param $ cmd */public function execBackend ($ cmd) {if (substr (php_uname (), 0, 7) = "Windows") {pclose (popen ("start cmd/c ". $ cmd, "r");} else {exec ($ cmd. ">/dev/null &");} return ;}