Summary of methods for invoking external shells by PHP

Source: Internet
Author: User
    1. System ("/usr/local/bin/webalizer/webalizer");
    2. ?>
Copy Code

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

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

Example:

    1. EXEC ("/bin/ls-l");
    2. EXEC ("/bin/ls-l", $res);
    3. # $res is a data, each element represents a row of results
    4. EXEC ("/bin/ls-l", $res, $RC);
    5. # The value of the $RC is the status code of the command/bin/ls-l. The case of success is usually 0
    6. ?>
Copy Code

PassThru () prototype: void PassThru (String command [, int return_var])

PassThru () only invokes the command, does not return any results, but outputs the result of the command directly to the standard output device. So the PassThru () function is often used to invoke programs such as Pbmplus (a tool for processing pictures under Unix, a stream of output binary raw images). It can also get the status code of the command execution.

Example:

    1. Header ("Content-type:image/gif");
    2. PassThru ("./ppmtogif hunte.ppm");
    3. ?>
Copy Code
  • 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.