views:

1406

answers:

4

I have a website cgi-bin program that is written in c++.

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

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

Would the c++ program still be able to read from stdin for POST commands or would it have to be read by the Perl or PHP and then forwarded.

+1  A: 

Learn about execv.

Watson Ladd
+2  A: 

You can use PHP's system() function to execute a shell command, which you could use to launch another program. The STDOUT of that program would then go to the same place as php's stdout (to the HTTP connection). You might have to do some messing around to get stdin to read from get/post/etc.

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

SoapBox
+4  A: 

You can use Perl's backticks or "system" commands to run shell commands. Also, perl has a lot of "Inline" classes that allow you to write code in other languages to be called in perl, including one for C++. If you can't find something that works, maybe you can make your own wrapper using that package.

gpojd
A: 

See my Awstats Wrapper blog post for some PHP code that solved my problem. My approach was to construct a command line that has the right environment variables set from the CGI query params and then do substitutions on the resulting output so that any links back to the CGI would go to my wrapper script instead. I also nuked the headers output from the CGI since PHP provides its own headers.

MattSmith