如何使用 php 运行 批处理文件?

How to run batch file using php?

如何在 wamp 服务器中执行批处理文件?在 Xampp 服务器上我得到正确的结果但是在 wamp 服务器上,得到空结果..

$gotIt = array();
$file111 = "C:/ABC/run.bat";
//echo $file; exit;
$kkk =  exec( $file111, $gotIt );
//echo $kkk;
$usr = implode("",$gotIt);
echo '<pre>'; print_r($usr);exit;

你试过吗?

system("cmd /C X:[PATH_TO_BAT_FILE]", &$output);

其中参数

/C = Carries out the command specified by the string and then terminates

&$output = Return value

你的情况

$gotIt = array();
$file111 = "C:/ABC/run.bat";

/** CMD cant return directly Array, but Text */
$CMDOutput = "";
system("cmd /C \"$file111\"", $CMDOutput);
 
/** Split output as you want (With Token, with preg_match, ...) */
$gotIt = mySplitFunction($CMDOutput);

/** 
 * EX. with explode where first param is a token (delimiter)
 *
 * If $CMDOutput contains "Pietro, terracciano", with this
 * instruction you obtain 
 *     $gotIt = array(
 *         'Pietro', 'Terracciano'
 *     );
 */
$gotIt = explode(',', $CMDOutput);

/** ... */