PHP retrieve external program data

后端 未结 2 782
别跟我提以往
别跟我提以往 2020-12-22 03:11

what I want to do is have a PHP script run a program and have it retrieve data somehow from it. For instance the program would parse data from a file and return the data for

相关标签:
2条回答
  • 2020-12-22 03:28

    If you need just the output of a command and/or can pass input to the external command on the command line, then exec() or passthru() is the way to go.

    If you need to be able to feed lengthier amounts of data into the external command than you can provide on a command line, you will need to pass it in via STDIN. I recommend using proc_open() which lets you call an external command, but also communicate with it through the standard input/output streams. You can see an example usage of it at http://www.php.net/manual/en/function.proc-open.php

    0 讨论(0)
  • 2020-12-22 03:34

    As per the manual page for exec(), you can pass an array to it as another parameter, and that array will be filled with the lines of output from the program.

    exec("Program.exe", $results);
    // $results is now an array where each element is a line of output
    
    0 讨论(0)
提交回复
热议问题