execute c++ program with php script

前端 未结 5 787
攒了一身酷
攒了一身酷 2020-12-15 09:57

I want to run a c++ code in php script. It takes 6 runtime arguments.
I am trying with:

exec(\"./controller.exe\",{\"125\", \"70\", \"127\", \"220\" ,\"0         


        
相关标签:
5条回答
  • 2020-12-15 10:24

    You can use PHP's system() to execute things via command line.

    0 讨论(0)
  • 2020-12-15 10:28

    You can use the call:

    exec("./controller.exe 125 70 127 220 0.5 0.4", $out);
    

    $out will hold the output if you are interested

    0 讨论(0)
  • 2020-12-15 10:32

    You can use this sample code:

    <?PHP
        $output=shell_exec("controller.exe 125 70 127 220 0.5 0.4");
        echo $output;
    ?>
    

    It is working very good for me. Place both controller.exe and xx.php in same folder.

    0 讨论(0)
  • 2020-12-15 10:40

    PHP scripts are run by php.exe so unless you have controller.exe in the same folder with php or your folder that contains controller.exe is in your path variable it wont work.

    Try giving it absolute path.

    The arguments should be passed in the same string as the executable, so something like this:

    exec("/c/project/controller.exe {'125', '70', '127', '220' ,'0.5', '0.4'}");
    
    0 讨论(0)
  • 2020-12-15 10:42

    To make your C++ code run on PHP you either specify the path of the code or put that code in the PHP folder. Then follow this command:

    exec("/c/project/controller.exe {'125', '70', '127', '220' ,'0.5', '0.4'}");
    

    To hold the output you can include another argument $output after curly braces. and print that output.

    0 讨论(0)
提交回复
热议问题