Worqy Posted February 1, 2011 Share Posted February 1, 2011 Hello. I'm looking for some help to make a script. The script should run a .bat file, and get the output from it. (The text from the console). Regards Worqy Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/ Share on other sites More sharing options...
Worqy Posted February 3, 2011 Author Share Posted February 3, 2011 Bump If you didn't understand what I explained, ask! Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169505 Share on other sites More sharing options...
Maq Posted February 3, 2011 Share Posted February 3, 2011 Hello. I'm looking for some help to make a script. The script should run a .bat file, and get the output from it. (The text from the console). Regards Worqy Pipe the output into a file or variable. Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169508 Share on other sites More sharing options...
AbraCadaver Posted February 3, 2011 Share Posted February 3, 2011 exec('c:\path\to\file.bat', $output); Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169509 Share on other sites More sharing options...
Worqy Posted February 3, 2011 Author Share Posted February 3, 2011 exec('c:\path\to\file.bat', $output); Thank you for your answer. I tried the code: <?php exec('d:\test\lol.bat', $output); echo $output; ?> and with the batch file: echo a echo b pause The only output I got is: Array Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169516 Share on other sites More sharing options...
Maq Posted February 3, 2011 Share Posted February 3, 2011 exec('c:\path\to\file.bat', $output); Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169517 Share on other sites More sharing options...
Maq Posted February 3, 2011 Share Posted February 3, 2011 Use: print_r($output): Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169519 Share on other sites More sharing options...
Worqy Posted February 3, 2011 Author Share Posted February 3, 2011 Use: print_r($output): Now the output is: Array ( [0] => [1] => D:\XAMPP\xampp\htdocs>echo a [2] => a [3] => [4] => D:\XAMPP\xampp\htdocs>echo b [5] => b [6] => [7] => D:\XAMPP\xampp\htdocs>pause [8] => Jatka painamalla mit„ tahansa n„pp„int„ . . . ) Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169530 Share on other sites More sharing options...
Maq Posted February 3, 2011 Share Posted February 3, 2011 ...Is that what you were expecting? Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169542 Share on other sites More sharing options...
Worqy Posted February 4, 2011 Author Share Posted February 4, 2011 No. I was expecting something like this: a b Regards Worqy Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1169796 Share on other sites More sharing options...
Worqy Posted February 5, 2011 Author Share Posted February 5, 2011 I now wan't to get the output out of a jar file insted of a batch file. I use the code: <?php exec('java -jar D:\test\server.jar', $result); print $result; ?> When i load the script, it opens the jar file, but the page keeps loading. Then when I close the jar file, the script stop loading and displays "Array". I would want to get the output of the jar as long as its open. Quote Link to comment https://forums.phpfreaks.com/topic/226329-run-bat-and-get-output/#findComment-1170222 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.