Home >Backend Development >PHP Tutorial >Introduction to the method of executing linux system commands in php
exec function Description: Execute external program. Syntax: string exec(string command, string [array], int [return_var]); Return value: string Detailed introduction: This function executes the external program or external instruction input command. Its return string is only the last line returned after the external program is executed; if you need a complete return string, you can use the PassThru() function. If the parameter array exists, the command will add the array to the parameter and execute it. If you do not want the array to be processed, you can call unset() before executing exec(). If both return_var and array parameters exist, the status after executing the command will be filled in return_var. It is worth noting that if you need to process the data entered by the user and prevent the user from playing tricks to crack the system, you can use EscapeShellCmd(). Example code:
popen function Description: Open the file. Syntax: int popen(string command, string mode); Return value: integer Detailed introduction: This function executes the command to open a file, and the file is processed by pipeline. Files opened with this function can only be one-way (read only or write only), and must be closed with pclose(). For file operations, fgets(), fgetss(), and fputs() can be used. If an error occurs while opening the file, a false value is returned. Example code:
|