Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute c++ program with php script

Tags:

c++

php

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", "0.4"});

But it is not working.

like image 224
sahil Avatar asked Nov 25 '10 16:11

sahil


People also ask

What language is PHP written in?

PHP as it's known today is actually the successor to a product named PHP/FI. Created in 1994 by Rasmus Lerdorf, the very first incarnation of PHP was a simple set of Common Gateway Interface (CGI) binaries written in the C programming language.


2 Answers

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

like image 197
Khaled Avatar answered Sep 21 '22 06:09

Khaled


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'}");
like image 31
Caner Avatar answered Sep 23 '22 06:09

Caner