-2

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..

Satya Chandra
  • 728
  • 2
  • 12
  • 26

1 Answers1

0

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)

mihutz
  • 195
  • 1
  • 3
  • 11
  • 1
    You can access it with: %1 | %0 is the filename, %1 is the first argument, %2 the second argument and so on. – mihutz Sep 27 '16 at 10:51
  • ok thanks it's working but one the way return result to php from bat it is giving or printing (echo ) only array. – Satya Chandra Sep 27 '16 at 11:21
  • 1
    The function should be exec, the shell_exec return string and have 1 parameter only – Phuong Oct 27 '17 at 05:15