Tham khảo tài liệu 'professional information technology-programming book part 82', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Executing Host Programs PHP can call an external program that resides on a web server in a number of different ways. Let s look at them in the following sections. The passthru Function The simplest way to run a host command and display the output to screen is by using the passthru function. The command passed in as an argument is executed on the web server and any resulting output is sent to the browser. The following is a simple example that works on both Unix Linux and Windows systems passthru hostname The command hostname is executed on the host system and its output is displayed. The hostname command finds the system s hostname and displays it. An optional second argument to passthru allows you to find the command s exit code. This is often useful if you want to find out whether a command succeededall programs should return an exit code of zero on successful completionor to perform a test on a command that could have several return values. Command Output Only the standard output stream is displayed in the web browser window so you must redirect the stderr stream if you want to see warnings and errors produced by the host command. For instance you can use passthru cmd 2 1 on a Unix server with the Bourne shell. The most common nonzero return values are 1 for a nonspecific error and 12 7 which means that the command you attempted to run could not be found. Other error codes specific to a particular program are usually documented. The following example makes a system call to the hostname command and takes an action depending on its return code passthru hostname return switch return case 0 echo Command completed successfully break case 127 echo Command could not be found break default echo Command failed with code return Using Backticks The backtick character is a handy shortcut that can be used to indicate a system command for execution on the web server itself. A string contained between two backticks is executed and the response produced by the host system is .