PHP怎样执行BAT文件,或者其他可执行文件??如果能下载直接运行也行

解决方案 »

  1.   

    相当于调用命令:exec
    (PHP 4, PHP 5)exec — Execute an external program说明
    string exec ( string $command [, array &$output [, int &$return_var ]] )
    exec() executes the given command. 参数command 
    The command that will be executed. output 
    If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec(). return_var 
    If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable. 
    返回值
    The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function. To get the output of the executed command, be sure to set and use the output parameter. 范例Example #1 An exec() example<?php
    // outputs the username that owns the running php/httpd process
    // (on a system with the "whoami" executable in the path)
    echo exec('whoami');
    ?> 
      

  2.   

    system
    (PHP 4, PHP 5)system — Execute an external program and display the output说明
    string system ( string $command [, int &$return_var ] )
    system() is just like the C version of the function in that it executes the given command and outputs the result. The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function. 参数command 
    The command that will be executed. return_var 
    If the return_var argument is present, then the return status of the executed command will be written to this variable. 
    返回值
    Returns the last line of the command output on success, and FALSE on failure. 范例Example #1 system() example<?php
    echo '<pre>';// Outputs all the result of shellcommand "ls", and returns
    // the last output line into $last_line. Stores the return value
    // of the shell command in $retval.
    $last_line = system('ls', $retval);// Printing additional info
    echo '
    </pre>
    <hr />Last line of the output: ' . $last_line . '
    <hr />Return value: ' . $retval;
    ?> 
      

  3.   

    exec函数,这个受系统限制,如果开启了安全模式,这个将不起作用