DOS System calls in Perl CGI under IIS 5.1

DOS System calls in Perl CGI under IIS 5.1

am 28.03.2006 13:37:26 von Birkyside

Good evening to all.

Has anyone had any experience in generating HTML output in their
CGI-scripting, using Windows system calls, in scripts that are running on
IIS web servers?

For example, I'm wondering how to go about displaying the result of a
Windows system call such as - system("tasklist");

to a browser, on a Windows XP server running Microsoft's IIS5.1?

The result of the system call is displayed in the browser when the script is
run on an Apache server, but there is no output in the browser when the
script is executed on the IIS server.

Can anyone suggest a solution to this problem?

Thanks in advance,
Geoff.

Re: DOS System calls in Perl CGI under IIS 5.1

am 28.03.2006 13:59:17 von Matt Garrish

"Birkyside" wrote in message
news:44291ffa$0$10672$afc38c87@news.optusnet.com.au...
> Good evening to all.
>
> Has anyone had any experience in generating HTML output in their
> CGI-scripting, using Windows system calls, in scripts that are running on
> IIS web servers?
>
> For example, I'm wondering how to go about displaying the result of a
> Windows system call such as - system("tasklist");
>
> to a browser, on a Windows XP server running Microsoft's IIS5.1?
>
> The result of the system call is displayed in the browser when the script
> is run on an Apache server, but there is no output in the browser when the
> script is executed on the IIS server.
>

I find that a bit hard to believe. system does not return the output from
the command. Are you really using backticks? And if not, you should be.
Please post the actual code where you get the command results if you want
more help.

The other common problem could be that IIS's IUSR has more restrictive
rights than Apache's anonymous user, so you're just not able to run the
command.

Matt

Re: DOS System calls in Perl CGI under IIS 5.1

am 28.03.2006 14:50:23 von Birkyside

Thanks Matt,
I appreciate your feedback.

Here's the Perl code for the CGI script:

#!c:\perl\bin\perl
# scrset1_10.pl - Developed: 27/03/2006
# This program is a Client/Server CGI algorithm to display the output
# of a DOS command in the browser. The command is passed to the CGI
# script from a text box.
#
use CGI ':standard';
my $Cmd;
$Cmd = param('txtCommand');
print("Content-type: text/html \n\n");
print(" \n \n Web-Based Command Prompt \n
\n");
print(" \n");
print("

\n

Web-Based Command Prompt

\n



\n");
print("
\n");
print("
The output of the command - " . $Cmd . " - is: \n");
print("
\n");
system($Cmd);
print("
\n");
print("
");
print("\n");
#end of script

Basically, I have a normal HTML page (see code for
below,) that contains a textbox (called txtCommand) in a form (frmDetails),
which is used to pass a DOS command (such as 'tasklist') to the CGI script
via form "posting" method, when the submit button is clicked.

The text typed in to the txtCommand text box is accepted to the variable
$Cmd in the CGI script (scrset1_10.pl) . This is then passed to the
system($Cmd); call which is then supposed to output the result of the
command to the CGI-generated page displayed in the user's browser.

The HTML code for the initial form is as follows:




Web Command Prompt

onLoad="window.document.frmDetails.txtCommand.focus()">


Web-Based Command Prompt






Enter the DOS command to execute :      











As I mentioned below, this worked as expected when I tested it via WAMP
server (Apache-based), but not on my IIS server.

I tested successfully also, a terminal version of the system call program
from the DOS command line:

#!c:\perl\bin\perl
# scrset1_10a.pl - Developed: 28/03/2006
# This program is a command-line algorithm to display the output
# of a DOS command in the terminal window. The command 'tasklist' is stored
in the variable $Cmd.
#
my $Cmd;
$Cmd = "tasklist";
system($Cmd);
#end of script

Output was as expected.

Again, thanks for your feedback.
Geoff.



"Matt Garrish" wrote in message
news:ky9Wf.1163$m35.110905@news20.bellglobal.com...
>
> "Birkyside" wrote in message
> news:44291ffa$0$10672$afc38c87@news.optusnet.com.au...
>> Good evening to all.
>>
>> Has anyone had any experience in generating HTML output in their
>> CGI-scripting, using Windows system calls, in scripts that are running on
>> IIS web servers?
>>
>> For example, I'm wondering how to go about displaying the result of a
>> Windows system call such as - system("tasklist");
>>
>> to a browser, on a Windows XP server running Microsoft's IIS5.1?
>>
>> The result of the system call is displayed in the browser when the script
>> is run on an Apache server, but there is no output in the browser when
>> the script is executed on the IIS server.
>>
>
> I find that a bit hard to believe. system does not return the output from
> the command. Are you really using backticks? And if not, you should be.
> Please post the actual code where you get the command results if you want
> more help.
>
> The other common problem could be that IIS's IUSR has more restrictive
> rights than Apache's anonymous user, so you're just not able to run the
> command.
>
> Matt
>

Re: DOS System calls in Perl CGI under IIS 5.1

am 29.03.2006 02:51:24 von Matt Garrish

"Birkyside" wrote in message
news:44293117$0$7605$afc38c87@news.optusnet.com.au...

[attribution corrected]

> "Matt Garrish" wrote in message
> news:ky9Wf.1163$m35.110905@news20.bellglobal.com...
>>
>> "Birkyside" wrote in message
>> news:44291ffa$0$10672$afc38c87@news.optusnet.com.au...

Try to avoid the TOFU posting style. You should always keep the context of
what you are referring to, as well as the proper attribution so anyone
jumping into the thread to help can easily figure out what's going on.

>>> The result of the system call is displayed in the browser when the
>>> script is run on an Apache server, but there is no output in the browser
>>> when the script is executed on the IIS server.
>>>
>>
>> I find that a bit hard to believe. system does not return the output from
>> the command. Are you really using backticks? And if not, you should be.
>> Please post the actual code where you get the command results if you want
>> more help.
>>
>
>
> Basically, I have a normal HTML page (see code for below,) that contains a textbox (called txtCommand) in
> a form (frmDetails), which is used to pass a DOS command (such as
> 'tasklist') to the CGI script via form "posting" method, when the submit
> button is clicked.
>

You think that's a good idea? How secure is this page? What if someone sends
in a nasty delete command?

> The text typed in to the txtCommand text box is accepted to the variable
> $Cmd in the CGI script (scrset1_10.pl) . This is then passed to the
> system($Cmd); call which is then supposed to output the result of the
> command to the CGI-generated page displayed in the user's browser.
>

Right, and system does not return any output from the command being run.
When you invoke a program that way, all you can get back is the exit status.
If you want to capture the output, use backticks.

>
> As I mentioned below, this worked as expected when I tested it via WAMP
> server (Apache-based), but not on my IIS server.
>
> I tested successfully also, a terminal version of the system call program
> from the DOS command line:
>

You may have fluked your way into the correct result. I don't have a WAMP
server to test on, but it may be intercepting the output from the shell and
sending it back to the browser. This is not the normal behaviour of system
nor of IIS, which is why it doesn't work under IIS. Try the following
instead:

print `tasklist`;

I expect you'll get the result you're looking for.

Matt

Re: DOS System calls in Perl CGI under IIS 5.1

am 29.03.2006 03:46:49 von Jim Gibson

In article , Matt Garrish
wrote:

> "Birkyside" wrote in message
> news:44293117$0$7605$afc38c87@news.optusnet.com.au...
>

> Right, and system does not return any output from the command being run.
> When you invoke a program that way, all you can get back is the exit status.
> If you want to capture the output, use backticks.
>
> >
> > As I mentioned below, this worked as expected when I tested it via WAMP
> > server (Apache-based), but not on my IIS server.
> >
> > I tested successfully also, a terminal version of the system call program
> > from the DOS command line:
> >
>
> You may have fluked your way into the correct result. I don't have a WAMP
> server to test on, but it may be intercepting the output from the shell and
> sending it back to the browser. This is not the normal behaviour of system
> nor of IIS, which is why it doesn't work under IIS. Try the following
> instead:
>
> print `tasklist`;
>
> I expect you'll get the result you're looking for.

What is the difference between system(tasklist) and print `tasklist`?
Both result in the output of tasklist going to the standard output of
the script. The web server is supposed to capture the standard output
of the script and send it to the browser. It is supposed to be valid
HTML, but if you bracket the output between

 and 
tags, you
can output pretty much anything that doesn't have special character
status.

I think the question should be why doesn't IIS do this?

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Re: DOS System calls in Perl CGI under IIS 5.1

am 29.03.2006 04:28:34 von Birkyside

Thanks Matt.

I appreciate the time you've taken to analyse what's happening and
offer your advice.

I will make the substitution as suggested and observe the outcome.

Regards,
Geoff

Re: DOS System calls in Perl CGI under IIS 5.1

am 29.03.2006 04:28:38 von Matt Garrish

"Jim Gibson" wrote in message
news:280320061746493692%jgibson@mail.arc.nasa.gov...
> In article , Matt Garrish
> wrote:
>
>> "Birkyside" wrote in message
>> news:44293117$0$7605$afc38c87@news.optusnet.com.au...
>>
>
>> Right, and system does not return any output from the command being run.
>> When you invoke a program that way, all you can get back is the exit
>> status.
>> If you want to capture the output, use backticks.
>>
>> >
>> > As I mentioned below, this worked as expected when I tested it via WAMP
>> > server (Apache-based), but not on my IIS server.
>> >
>> > I tested successfully also, a terminal version of the system call
>> > program
>> > from the DOS command line:
>> >
>>
>> You may have fluked your way into the correct result. I don't have a WAMP
>> server to test on, but it may be intercepting the output from the shell
>> and
>> sending it back to the browser. This is not the normal behaviour of
>> system
>> nor of IIS, which is why it doesn't work under IIS. Try the following
>> instead:
>>
>> print `tasklist`;
>>
>> I expect you'll get the result you're looking for.
>
> What is the difference between system(tasklist) and print `tasklist`?
> Both result in the output of tasklist going to the standard output of
> the script. The web server is supposed to capture the standard output
> of the script and send it to the browser. It is supposed to be valid
> HTML, but if you bracket the output between

 and 
tags, you
> can output pretty much anything that doesn't have special character
> status.
>

Does system print to your script's STDOUT? I wouldn't expect IIS to output
the result of a command being run within a script back to the browser. And
I'm almost positive that when you're running under the perlis.dll the output
of any system command definitely will not make it's way back into your
program's stdout. Maybe I'm confusing that behaviour with what it should do,
in which case I stand corrected.

Matt

Re: DOS System calls in Perl CGI under IIS 5.1

am 29.03.2006 05:06:03 von Birkyside

Yes, I get the correct output to my DOS terminal's STDOUT when I run a
modified version of the script directly from a DOS command line.

The modified version does not output HTML tags, just the result of the
system call. To achieve this, I hard-coded a value of "tasklist" (for
testing purposes) to the variable $Cmd and passed this variable as an
argument to the system call as follows:

my $Cmd = "tasklist";
system($Cmd);

When I ran the script from the command line, the output was as expected
in STDOUT.

Geoff

Re: DOS System calls in Perl CGI under IIS 5.1

am 29.03.2006 10:19:42 von someone

Jim Gibson wrote:
> In article , Matt Garrish
> wrote:
>>
>>print `tasklist`;
>>
>>I expect you'll get the result you're looking for.
>
> What is the difference between system(tasklist) and print `tasklist`?
> Both result in the output of tasklist going to the standard output of
> the script.

Assuming of course that the currently selected filehandle is STDOUT.

:-)


John
--
use Perl;
program
fulfillment

Re: DOS System calls in Perl CGI under IIS 5.1

am 29.03.2006 12:39:31 von Joe Smith

Birkyside wrote:
> Yes, I get the correct output to my DOS terminal's STDOUT when I run a
> modified version of the script directly from a DOS command line.

We already know that works. The question is: When a command
is run via system() by perl inside of IIS, is the command's STDOUT
attached to the same file handle that perl is using for its output.

I remember a time when Windows web servers did no do cgi-bin.
It did cgi-win instead. Instead of looking at ENV variables,
reading from STDIN and writing to STDOUT, programs were given
the names of three files. One had the ENV data, the second
had any POST data (which has been completely read in before the
cgi-win program started). The third file is where the cgi-win
program was to send its output (instead of writing to STDOUT).
The data from the third file would be sent back to the browser
by the server only after the cgi-win program completed.

In that set-up, data written to STDOUT would get thrown into
the bit bucket.

-Joe