CGI Execution

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
firkinfedup
Forum Newbie
Posts: 19
Joined: Sat Dec 04, 2004 7:25 am

CGI Execution

Post by firkinfedup »

Hi there,

I'm currently attempting to execute CGI binaries within my cgi-bin directory. I've *just* managed to get some output but I have something weird happening too, it seems that a load of other information is being outputted also, and it looks like its the contents of the exe that's being executed.

I'm executing it using the following code in an SHTML file,

<!--#exec cgi="/cgi-bin/helloworld.exe"-->

Unfortunately this was the only way I could get a binary script to work. Does anyone know any other way I can run it? I would *ideally* like to execute it from a php script, but haven't found the correct way yet,

Also, just to add to my confusion (cos I'm new at this stuff) , could I ask the following,

*) If I rename my exe to cgi and execute it in the same way I get some HTTP status code 502. Why is this?

*) If I rename my exe to cgi and attempt to navigate to the url I get nothing except an error "The specified CGI application misbehaved by not returning a complete set of HTTP headers.", how comes? I have attempted to output *all* headers as a response but still it fails.

*) If I just naviate to the url of the exe the browser attempts to download it, I presume this is completely normal?

*) Can I name it as an exe and simply execute it using the system function and capture the output in that way?

I'm not quite sure of the normal procedures for CGI but I'm attempting to create a VB.NET CGI application and call it within PHP files, so far I have both VB.NET and C 'hello world' CGI apps and they both output this extra spurious info.

Thanks loads in advance and my appologies for the lengthy stupid questions!

Nick.
firkinfedup
Forum Newbie
Posts: 19
Joined: Sat Dec 04, 2004 7:25 am

Working 100% from SHTML

Post by firkinfedup »

Hi again,

Well I've finally got one working, a VB.NET CGI application being executed via an SHTML page with '<!--#exec cgi="/cgi-bin/helloworld.exe"-->' and nothing else in the page.

Unfortunately I would still like to mix with PHP code if possible, so is there any way that I can throw this into a PHP page rather than SHTML?

Nick.
firkinfedup
Forum Newbie
Posts: 19
Joined: Sat Dec 04, 2004 7:25 am

At last

Post by firkinfedup »

I've finally got it working woth the following PHP script,

Code: Select all

<?php
$cmd = '<.net executable path>';
$outputfile = '<tempfile path.>';
$cmdline = "cmd /C $cmd > $outputfile";
$WshShell = new COM("WScript.Shell");  
$oExec = $WshShell->Run($cmdline, 0, true); 
readfile($outputfile);
unlink($outputfile);
?>
I'm thinking it would be allot nicer if the output was sent straight to screen rather than to a file, so I shall have to mess around with it some more. This enables you to make a .NET console application and execute it in the cgi-bin directory whilst capturing any output.

Nick
?>
Post Reply