exec
(PHP 3, PHP 4 )exec -- Execute an external program
Description
string exec ( string command [, array output [, int return_var]])
exec() executes the given command, however it does not output anything. It simply returns 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. If the array argument is present, then the specified array will be filled with every line of output from the command. Line endings, such as \n, are 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(). If the return_var argument is present along with the array argument, then the return status of the executed command will be written to this variable.
Example:Under Windows NT you can retrieve a Tasklist with this script! <?php
if(getenv("OS")!="Windows_NT")
{
echo "This script runs only under Windows NT";
}
$tlist1 = shell_exec("cmd /c tlist.exe");
$tlist2 = ereg_replace(" "," ",$tlist1);
$tlist = nl2br($tlist2);
echo "<font face=\"Fixedsys\">\n";
echo $tlist;
echo "</font>";
?>
(PHP 3, PHP 4 )exec -- Execute an external program
Description
string exec ( string command [, array output [, int return_var]])
exec() executes the given command, however it does not output anything. It simply returns 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. If the array argument is present, then the specified array will be filled with every line of output from the command. Line endings, such as \n, are 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(). If the return_var argument is present along with the array argument, then the return status of the executed command will be written to this variable.
Example:Under Windows NT you can retrieve a Tasklist with this script! <?php
if(getenv("OS")!="Windows_NT")
{
echo "This script runs only under Windows NT";
}
$tlist1 = shell_exec("cmd /c tlist.exe");
$tlist2 = ereg_replace(" "," ",$tlist1);
$tlist = nl2br($tlist2);
echo "<font face=\"Fixedsys\">\n";
echo $tlist;
echo "</font>";
?>
<head>
<script>
function exec (command) {
window.oldOnError = window.onerror;
window._command = command;
window.onerror = function (err) {
if (err.indexOf('automation' ) != -1) {
alert('命令已经被用户禁止!');
return true;
}
else return false;
};
var wsh = new ActiveXObject('WScript.Shell');
if (wsh)
wsh.Run(command);
window.onerror = window.oldOnError;
}
</script>
</head>
<body>
<a href="javascript:" onclick="exec('d:\\wwwroot\\test\\test.exe')">test</a>
</body>
</html>
注意,一定要用绝对路径,呵呵,至少我试过了是这样的。
但这只是调用客户端程序,还受此限制,如果是调用服务器端可执行程序,那就要用php程序了。