- <? Php
- $ Last_line = system ("ls", $ retval );
- Echo "Last line of the output:". $ last_line;
- Echo" Return value: ". $ retval;
- ?>
Exec function description: execute an external program. Syntax: string exec (string command, string [array], int [return_var]); return value: string
Details: This function executes the external program or external command that inputs the command. The returned string is the last line returned after the execution of the external program. to return the complete string, you can use the PassThru () function.
If the parameter array exists, the command adds the array to the parameter for execution. if you do not want the array to be processed, you can call unset () before executing exec (). If both the return_var and array parameters exist, the status after the command is executed is filled in return_var.
It is worth noting that EscapeShellCmd () can be used to process user input data and prevent users from cracking the system by means of tricks ().
Instance code:
- <? Php
- Echo exec ("whoami ");
- ?>
Popen function description: open a file. Syntax: int popen (string command, string mode); return value: integer
Detailed introduction: This function executes commands to open a file, which is a file processed in pipelines. Files opened using this function can only be one-way (read-only or write-only), and must be closed using pclose. You can use fgets (), fgetss (), and fputs () in file operations (). If an error occurs when the file is opened, the value false is returned.
Instance code:
- <?
- $ Fp = popen ("/bin/ls", "r ");
- ?>
|