Run C++ script in PHP

前端 未结 2 1084
有刺的猬
有刺的猬 2020-12-11 05:34

I have a C++ program that needs to take data from a PHP script, process it, and return the data to my PHP script.

  1. How do you pass the values from PHP to C++?<
2条回答
  •  渐次进展
    2020-12-11 06:14

    1 . How do you pass the values from PHP to C++?

    Ans: In php file, you could use exec function to execute your C++ binary file. Example:

    exec("/path/to/your/binary $var1 $var2", $output);
    

    2 . How do you run the C++ script? Do you have to compile it first some how?

    Ans: Of course, you can't execute the C++ script directly, C++ is compiled language, you could just execute the binary file.

    3 . How do you get the values out of the C++ script?

    Ans: See 1, you will get the output form C++ by $output.

提交回复
热议问题