How to pass variable from php to bat file and read its result?

 ̄綄美尐妖づ 提交于 2019-12-10 12:27:08

问题


How to pass variable from php to bat file and get back the result. I tried as follows

<?php
    $input="layer";
    echo shell_exec("F:\xampp\htdocs\flood_publish\123.bat",$input)
?>

and how to access and use that variable in bat file..


回答1:


You can pass variables to bat files as arguments and the "$input" variable from your example contains the output of the bat file. So, if you want to pass a variable to a bat file and get the output back to the php, you should write something like this:

$input="layer";
exec("F:\xampp\htdocs\flood_publish\123.bat $input",$output);
print_r($output);

Here you can find more about how to use arguments in .bat files: Get list of passed arguments in Windows batch script (.bat)



来源:https://stackoverflow.com/questions/39701896/how-to-pass-variable-from-php-to-bat-file-and-read-its-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!