1. the problem is that you need to execute a shell script in the php code and want to get stdout and stderr respectively ). Using shell redirection to put the standard output and error output into the file and then using php to read the file is feasible, but the output file content is no longer needed after it is returned to php... 1. problem
Execute a shell script in the php code.RespectivelyGet itsStandard output (stdout)AndError output (stderr). Using shellRedirectionIt is feasible to put the standard output and error output into the file and then use php to read the file. but it is no longer necessary to return the content of the output file to php. Is there a way to redirect the shell output to the variable?
To execute the script function, php itself cannot be used to complete (execute the R language script), and regular output and error output must be fed back.
2. an attempt has been made.
In shellRedirectionStandard output and error output can be put into files respectively, but temporary files are generated.
my_cmd 1>out.txt 2>err.txt
Php re-readout.txtAnderr.txtFile content.
The disadvantage is that an intermediate file is generated. If the shell commandmy_cmdThe execution time is relatively long (may take several minutes), so if the same user initiates an http request multiple times within a short period of time, php will executemy_cmd, You needout.txtAnderr.txtTo avoid write conflicts. This isGenerated many unnecessary intermediate files. Even if they are deleted in a timely manner, I/O is overhead and hopefully avoided.
Phpexec()Function:
string exec ( string $command [, array &$output [, int &$return_var ]] )
Parameters in$outputIt seems that only the "screen output during script running" content can be obtained, which is a mixture of stdout, stdout, and stderr, and cannot be obtained separately.