1

I am planning on putting the executable of a C program in a server and running it using a PHP script - as a Web API: e.g. echo exec("myscript.exe")

Currently the myscript runs on command prompt - it takes two input files and return an integer or float number. Currently the code takes the input files on the command prompt.

What modifications are needed to the existing program - I heard about HTTP bridge and daemon but not sure what I need, if any?

Update: Currently the only other dependency is libsndfile - that is available on Linux. The C program was developed on Linux.

Jordan Miner
  • 2,034
  • 17
  • 19

2 Answers2

0

The answer actually depends on the APIs the C application is using. If the C application is using just the Standard C library, then you just need to recompile the application on the target system and invoke the name of the executable. However if you depend on any Windows based APIs such as COM, WinINET, etc you will need to run the executable on another system and have some sort of IPC mechanism between them.

Mark
  • 1,128
  • 13
  • 21
  • C program does not depend on COM, WinINET, etc. It however uses sndfile - C program was developed on Ubuntu. – user4504270 Feb 06 '15 at 23:08
  • So just recompile in the target server environment and run it with php scripts ... nothing else is needed? – user4504270 Feb 06 '15 at 23:09
  • Yes, everything should be otherwise fine. A fair warning: From my experience porting and running applications under different environments exposes bugs which were innocuous or otherwise didn't exhibit under the original system. If you find a comment, answer, or response helpful, please remember to up vote to reward the writer for their time! If you find answer particularly helpful after a few days please mark that answer as accepted. – Mark Feb 06 '15 at 23:19
  • Thank you Mark - why some people talk about http bridge and daemon? Does running as a daemon give any benefit? – user4504270 Feb 06 '15 at 23:55
  • I don't see any comments here regarding bridges and daemons; however depending on your application there may be advantages to using architectures other than a process-per request. – Mark Feb 07 '15 at 00:21
  • Sorry, it was not in this thread ... Daemon etc. Thanks Mark. – user4504270 Feb 07 '15 at 00:32
  • If you found my answers helpful or useful would you mind up voting them so I can get feedback on what is useful? ty – Mark Feb 07 '15 at 01:06
0

Quick and simple (assuming your ouptut is a single text line on stdout:

exec("yourprog.exe file1 file2",$res);
echo "result is " . $res[0];
James Anderson
  • 27,109
  • 7
  • 50
  • 78
  • As per your code, "yourprog.exe file1 file2", will give me a set of numbers, say 2, 23, 54, 23, 43. Assume that there will always be 5 set of numbers. When I implemented the code above, $res did not catch the output - but rather gives the initialization value - how should I initialize $res? Why $res is not capturing the output? – user4504270 Feb 12 '15 at 00:00