Php server response to android when executing a batch file

有些话、适合烂在心里 提交于 2020-01-05 08:43:00

问题


I have an application which is in java & i have created a batch file(.bat) of that application & running it in php like this

   <?php
      system ("cmd.exe /c final.bat");
   ?>

The output is something like this

C:\wamp\www\php>java -jar Most closely reseambling is this...C:\wamp\www\php>pause Press any key to continue . . .

I am invoking this through my android application & want this out as response...Can you tell me how to do this .... It would be great if I would be able to eliminate prompts from response.


回答1:


Check out the exec function. Instead of automatically printing the output, it will return the output as a string, or in an optional array of lines in the second argument. You can then parse this string or array and print only what you need.

Example which would print all but the first line of output:

exec('cmd.exe /c final.bat',$output);
for($i = 1; $i < count($output); ++$i) echo $output[$i],'<br />';



回答2:


system returns any output from the command, so a simple

echo system(...);

would do the trick. To be able to send text as input to the invoked command, you should look into using popen() instead, which lets you "use" the invoked command as if you were using it from a shell/command prompt.

Note that system will block until the external program finishes. In your case, with it sitting there with "press any key to continue", this will never happen and your PHP process will just sit there indefinitely (or until max_execution_time is exceeded, whichever comes first).



来源:https://stackoverflow.com/questions/5967418/php-server-response-to-android-when-executing-a-batch-file

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