Home  >  Article  >  Backend Development  >  Summary of methods for calling external shell in php

Summary of methods for calling external shell in php

WBOY
WBOYOriginal
2016-07-25 09:03:331018browse
  1. system("/usr/local/bin/webalizer/webalizer");
  2. ?>
Copy code

exec() Prototype: string exec (string command [, string array [, int return_var]])

The exec() function is similar to system(). It also executes the given command, but does not output the result, but returns the last line of the result. Although it only returns the last line of the command result, using the second parameter array can get the complete result by appending the results line by line to the end of the array. So if the array is not empty, it is best to use unset() to clear it before calling it. Only when the second parameter is specified, the third parameter can be used to obtain the status code of command execution.

Example:

  1. exec("/bin/ls -l");
  2. exec("/bin/ls -l", $res);
  3. #$res is a data, each element A line representing the result
  4. exec("/bin/ls -l", $res, $rc);
  5. #The value of $rc is the status code of the command /bin/ls -l. In case of success, it is usually 0
  6. ?>
Copy code

passthru() Prototype: void passthru (string command [, int return_var])

passthru() only calls the command and does not return any results, but outputs the running results of the command directly to the standard output device as is. Therefore, the passthru() function is often used to call programs like pbmplus (a tool for processing images under Unix that outputs a binary stream of original images). It can also get the status code of command execution.

Example:

  1. header("Content-type: image/gif");
  2. passthru("./ppmtogif hunte.ppm");
  3. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn