How to pass variable from php to bat file and read

2019-06-14 19:25发布

问题:

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)