System program execution

Source: Internet
Author: User
Tags posix stdin
System program Execution: String Escapeshellarg (String $arg) to escape strings for ' shell commands ' Escapeshellarg string (string $arg) to ' shell life The parameter ' string of the order escapes the warning: in the following 4 functions that call system commands, you should call these 2 functions before use, and escape the ' command ' and ' arguments ' respectively, string exec (string $command [, Array & $o utput [, int & $return _var]]) string System (String $command [, int & $return _var]) void PassThru (string $command [, int & $return _var]) string shell_exec (string $cmd) execution operator: 1.PHP supports an execution operator: an inverted quotation mark ('). Note that this is not a single quote.
		PHP will attempt to execute the contents of the inverted quotation mark as a shell command and return its output information (that is, it can be assigned to a variable rather than simply discarded to the standard output).
		2. The effect of using the inverted quote operator "'" is the same as the function shell_exec (). Note: 1. The inverse quotation mark operator is not valid when Safe mode is activated or when shell_exec () is turned off.
			-----inverted quotes, the effect is the same as ' shell_exec () ', conjecture is not directly called ' shell_exec () ', so it is not available if ' shell_exec () ' is disabled.
		2. Unlike some other languages, inverted quotes cannot be used in double quote strings.		Example: <?php $output = ' ls-al ';
			Note: Is the direct inverted quote echo "<pre> $output </pre>"; ?> Warning: The above 4 system call functions are very similar and are all system calls. There are subtle differences, you can see the reprint of another article: http://blog.csdn.net/beyond__devil/article/details/53868309 can also directly read the manual, very simple PROc_* related functions: Resource Proc_open (string $cmd, array $descriptorspec, array & $pipes [, String $cwd [, array $env [, a
			Rray $other _options]]) 1. Executes a command and opens a file pointer for input/output.
			2. Similar to the Popen () function, but Proc_open () provides the ability to perform more powerful control procedures. Parameters: $cmd-the command to execute $DESCRIPTORSPEC-an indexed array.
					The key of the array represents the descriptor, and the array element value indicates how PHP will transfer these descriptors to the child process. Array index: 0-standard input (STDIN) 1-standard output (STDOUT) 2-standard error output (stderr) file descriptor values are not limited to 0,1 and 2, you can use any valid file descriptor and transfer it To the child process. This allows your script to interoperate with other scripts.
					For example, you can specify file descriptors to transfer passwords in a more secure manner to such pgp,gpg and OpenSSL programs, and you can easily obtain state information for these programs. Array element value: 1. Contains descriptive information about the pipeline to be routed to the process.
							is also an array, the first element is a description type character, and the second element is the option that is true for that descriptor. The 1> type is: pipe, the second element can be: R routes the read end of the pipe to the process, and the write-end 2> type of the pipe to the process is: file, the second element is: file name 2. A stream resource type that represents a real file descriptor (for example, an open file,
				A socket port, STDIN).
				$pipes-will be placed as an indexed array with elements that are created by the executing program that correspond to the file pointers to the PHP end. $CWD-The initial working directory to execute the command. Must be ' absolute path ', setting this parameter to NULL indicates the use of the default value (the working directory of the current PHP process) $env-the environment variable used by the command to execute.
				Setting this parameter to NULL means using the same environment variable as the current PHP process. $other _options-Used by the command to be executedEnvironment variables.
					Setting this parameter to NULL means using the same environment variable as the current PHP process.
					Suppress_errors (Windows platform only): set to TRUE to suppress errors generated by this function.

		Bypass_shell (Windows platform only): set to TRUE to bypass the Cmd.exe shell. int Proc_close (Resource $process) closes the process opened by Proc_open () and returns the process exit code warning: the Proc_close () function waits for the process to terminate and returns the return value of the process.
			If you have an open pipe that is connected to a process, you need to call the fclose () function before calling this function to close the pipe, or it will throw a deadlock-the subprocess will not exit when the pipe is open. Return value: Returns the end status code of the process.

		If an error occurs, returns-1. BOOL Proc_nice (int $increment) modifies the priority of the current process and the amount of modification is specified by the increment parameter.
			Increment to a positive number lowers the current process priority, whereas negative numbers increase the priority.
				Warning: 1.proc_nice () and Proc_open () functions as well as functions related to Proc_open () are irrelevant. 2. Discovery: There is no "resource $process" here, where the priority of the current process is adjusted. Rather than the process we open through ' proc_open () '.


		This leads to the possibility that we are using pcntl&posix extensions. BOOL Proc_terminate (Resource $process [, int $signal = 15]) 1. Sends a signal to the process (created by the Proc_open () function) to notify it of termination.
			After the proc_terminate () call returns immediately, without waiting for the process to terminate. 2. You can use Proc_terminate () to terminate the process and continue with other tasks.
			You can use the Proc_get_status () function to check whether a process has terminated.
				Parameters: $process-Resource opened by Proc_open (). $signAl-Optional parameters, only for POSIX operating systems. Represents the signal that the system command Kill (2) is invoked to send to the process.
			The default value is Sigterm. Warning: This function has a serious bug. Terminates the current process, but does not abort the child process of the current process. (probably the so-called zombie process) can be viewed in the manual: Http://php.net/manual/zh/function.proc-terminate.php.

		There are other people to give the solution, here is not excerpt.
			Array Proc_get_status (Resource $process) gets information about the process opened by the Proc_open () function.
			Parameters: $process-The process resource that is opened by Proc_open () to check. Return value: If the call succeeds, returns an array containing the process information, False if an error occurs.
					The returned array contains the following elements: an element type description command string passing in the Proc_open () function's command-line string. PID int process ID running bool True indicates that the process is still running, and FALSE indicates that the process has terminated signaled bool true to indicate that the child process was terminated by an signal.
					On the Windows platform is always FALSE. stopped bool TRUE indicates that the child process is signaled to stop.
					On the Windows platform is always FALSE. The exit code for the ExitCode int process (meaningful only if running is FALSE).
					The actual value is returned only the first time the function is called, and subsequent calls return-1.
					Termsig int causes a child process to terminate the execution of the signal value (only if signaled is TRUE).

		Stopsig int causes a child process to stop executing a signal value (only if stopped is TRUE).
				 Example: <?php $descriptorspec = Array (0 => array ("Pipe", "R"),//standard input, child process reading data from this pipeline  1 => Array ("Pipe", "w"),//standard output, the subprocess writes data to this pipeline 2 => array ("File", "/tmp/error-output.txt", "a")/standard error, written to

				a document);
				$CWD = '/tmp ';

				$env = Array (' some_option ' => ' aeiou ');		$process = Proc_open (' php ', $descriptorspec, $pipes, $CWD, $env);
				    1.proc_open () if (Is_resource ($process)) {//$pipes now looks like this:///0 => can write handle to child process standard input 1 => the handle//error output that can be read from the child process standard output is appended to the file/tmp/error-output.txt fwrite ($pipes [0], ' <?php print_r ($_en
				    V);?> ');		Fclose ($pipes [0]);
				    2. Before Proc_close (), close all pipe pipe echo stream_get_contents ($pipes [1]);		Fclose ($pipes [1]);
				    2. Before Proc_close (), close all pipe pipes//Remember: Close all pipes before calling Proc_close to avoid deadlocks.		$return _value = Proc_close ($process);
				3.proc_close () echo "command returned $return _value\n"; ?> output: Array ([some_option] => aeiou [PWD] =>/tmp [SHLVL] => 1 [_] =>/usr/local/bin/php) command returned 0 functions similar to Proc_open () are: Popen ()-opens a pipeline to the process that is generated by the derivation of a given command command.
		Returns the same file pointer returned by a fopen (), except that it is one-way (only for reading or writing) and must be closed with pclose ().
 fopen ()-Open file or URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.