DOS System calls in Perl CGI under IIS 5.1

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.
Birkyside [ Di, 28 März 2006 13:37 ] [ ID #1250259 ]

Re: DOS System calls in Perl CGI under IIS 5.1

"Birkyside" <birkyside [at] optunet.com.au> wrote in message
news:44291ffa$0$10672$afc38c87 [at] 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
Matt Garrish [ Di, 28 März 2006 13:59 ] [ ID #1250260 ]

Re: DOS System calls in Perl CGI under IIS 5.1

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("<HTML> \n <HEAD> \n <TITLE> Web-Based Command Prompt </TITLE> \n
</HEAD>\n");
print("<BODY bgcolor=\"#DDDDFF\" TEXT=\"#OOOAAA\"> \n");
print("<center> \n <H1>Web-Based Command Prompt</H1> \n
</center></BR></BR></BR>\n");
print("<DIV>\n");
print("<BR>The output of the command - " . $Cmd . " - is: \n");
print("<PRE>\n");
system($Cmd);
print("</PRE>\n");
print("</DIV>");
print("</BODY>\n</HTML>");
#end of script

Basically, I have a normal HTML page (see code for <!-- scrset1_10.html -->
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:

<!-- scrset1_10.html -->
<HTML>
<HEAD>
<TITLE>Web Command Prompt</TITLE>
</HEAD>
<BODY BGCOLOR="#DDDDFF", TEXT="#000AAA",
onLoad="window.document.frmDetails.txtCommand.focus()">
<FORM NAME="frmDetails", METHOD="post", ACTION="cgi-bin/scrset1_10.pl">
<DIV align="center">
<H1>Web-Based Command Prompt</H1><BR><BR><BR>

Enter the DOS command to execute :      
<INPUT TYPE="text" NAME="txtCommand" SIZE="20">
</DIV>
<DIV align="center">
<BR>
<INPUT TYPE="submit" NAME="cmdSubmit" VALUE="Execute">
<INPUT TYPE="reset" NAME="cmdReset" VALUE="Clear">
</DIV>
</BODY>
</HTML>

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" <matthew.garrish [at] sympatico.ca> wrote in message
news:ky9Wf.1163$m35.110905 [at] news20.bellglobal.com...
>
> "Birkyside" <birkyside [at] optunet.com.au> wrote in message
> news:44291ffa$0$10672$afc38c87 [at] 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
>
Birkyside [ Di, 28 März 2006 14:50 ] [ ID #1250261 ]

Re: DOS System calls in Perl CGI under IIS 5.1

"Birkyside" <birkyside [at] optunet.com.au> wrote in message
news:44293117$0$7605$afc38c87 [at] news.optusnet.com.au...

[attribution corrected]

> "Matt Garrish" <matthew.garrish [at] sympatico.ca> wrote in message
> news:ky9Wf.1163$m35.110905 [at] news20.bellglobal.com...
>>
>> "Birkyside" <birkyside [at] optunet.com.au> wrote in message
>> news:44291ffa$0$10672$afc38c87 [at] 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 <!--
> scrset1_10.html --> 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
Matt Garrish [ Mi, 29 März 2006 02:51 ] [ ID #1251963 ]

Re: DOS System calls in Perl CGI under IIS 5.1

In article <dSkWf.1483$u15.302172 [at] news20.bellglobal.com>, Matt Garrish
<matthew.garrish [at] sympatico.ca> wrote:

> "Birkyside" <birkyside [at] optunet.com.au> wrote in message
> news:44293117$0$7605$afc38c87 [at] 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 <pre> and </pre> 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
Jim Gibson [ Mi, 29 März 2006 03:46 ] [ ID #1251964 ]

Re: DOS System calls in Perl CGI under IIS 5.1

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
Birkyside [ Mi, 29 März 2006 04:28 ] [ ID #1251965 ]

Re: DOS System calls in Perl CGI under IIS 5.1

"Jim Gibson" <jgibson [at] mail.arc.nasa.gov> wrote in message
news:280320061746493692%jgibson [at] mail.arc.nasa.gov...
> In article <dSkWf.1483$u15.302172 [at] news20.bellglobal.com>, Matt Garrish
> <matthew.garrish [at] sympatico.ca> wrote:
>
>> "Birkyside" <birkyside [at] optunet.com.au> wrote in message
>> news:44293117$0$7605$afc38c87 [at] 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 <pre> and </pre> 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
Matt Garrish [ Mi, 29 März 2006 04:28 ] [ ID #1251966 ]

Re: DOS System calls in Perl CGI under IIS 5.1

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
Birkyside [ Mi, 29 März 2006 05:06 ] [ ID #1251967 ]

Re: DOS System calls in Perl CGI under IIS 5.1

Jim Gibson wrote:
> In article <dSkWf.1483$u15.302172 [at] news20.bellglobal.com>, Matt Garrish
> <matthew.garrish [at] sympatico.ca> 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
someone [ Mi, 29 März 2006 10:19 ] [ ID #1251968 ]

Re: DOS System calls in Perl CGI under IIS 5.1

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
Joe Smith [ Mi, 29 März 2006 12:39 ] [ ID #1251969 ]
Perl » alt.perl » DOS System calls in Perl CGI under IIS 5.1

Vorheriges Thema: LWP Authentication Problem
Nächstes Thema: Concatenating Audio Files in with Perl on a Mac