How to call C ++ binary from Perl or PHP (CGI-BIN using Apache on Linux)?

I have a website cgi-bin program written in C ++.

Unfortunately the website provider for my friend site only allows cgi-bin scripts in Perl or PHP.

Is there an easy way to just have a very small Perl or PHP wrapper that just calls the compiled C ++ binary?

Will the C ++ program still read stdin for POST commands or should it be read by Perl or PHP and then redirected.

+1


source to share


3 answers


You can use Perl callbacks or "system" commands to run shell commands. Also, there are many "Inline" classes in perl that allow you to write code in other languages ​​to call in perl, including C ++ . If you can't find something that works, perhaps you can do your own own wrapper using this package.



+4


source


You can use the PHP system () function to execute a shell command that you could use to start another program. This program's STDOUT will then go to the same location as php stdout (to the HTTP connection). You may need to do a bit of work to get the stdin to read from get / post / etc.



But most likely, the website provider has disabled the ability to execute programs in this way. This could be a security risk, and if they specifically only allow php and perl, then they will probably specifically disable as many non-php / perl methods as possible. So, the short answer is: you are probably out of luck.

+2


source


See my Awstats Wrapper blog post for some PHP code that solved my problem. My approach was to build the command line with the correct environment variables given from the CGI query parameters, and then do substitutions on the resulting output so that any references back to CGI go to my shell script. I also disabled the output of headers from the CGI since PHP provides its own headers.

0


source







All Articles