Perls system() call fails in a cgi-file running on win2k and apache

M

Mr. Zeus

I am running a UseMod wiki and tried to implement some system calls
using the perl command system(@args). In my case it was a call of an
executable file.
Path to the file was fully given as well as the proper settings of
@args.
Independant of the function (dos-command or exe) I am calling it
doesn't work.

The system I am using is:
W2K SR2
apache 2.0.50 (win32)
Perl 5.8.4

Are there additional mods necessary in the apache config?
What to do exactly?

Thanks for your help
Zeus
 
A

A. Sinan Unur

(e-mail address removed) (Mr. Zeus) wrote in
I am running a UseMod wiki and tried to implement some system calls
using the perl command system(@args). In my case it was a call of an
executable file.
Path to the file was fully given as well as the proper settings of
@args.
Independant of the function (dos-command or exe) I am calling it
doesn't work.

Please read the posting guidelines posted here frequently. You have given
no useful information and you did not describe your problem (does not work
does not count).
The system I am using is:
W2K SR2
apache 2.0.50 (win32)
Perl 5.8.4

Good for you.
Are there additional mods necessary in the apache config?
What to do exactly?

Thanks for your help
Zeus

Find a telepath.

Sinan.
 
J

James Willmore

Mr. Zeus said:
I am running a UseMod wiki and tried to implement some system calls
using the perl command system(@args). In my case it was a call of an
executable file.
Path to the file was fully given as well as the proper settings of
@args.
Independant of the function (dos-command or exe) I am calling it
doesn't work.

The system I am using is:
W2K SR2
apache 2.0.50 (win32)
Perl 5.8.4

Are there additional mods necessary in the apache config?
What to do exactly?

Thanks for your help
Zeus

You have provided no code, so we can't see *what* you're trying to do.
All we know for certain is that you have some issue with using 'system'.

Try *reading* the Perl documentation on using 'system' ("perldoc -f
system" on the command line -or- visit http://www.perldoc.com/ and
search for 'system').

HTH

Jim
 
M

Mr. Zeus

James Willmore said:
You have provided no code, so we can't see *what* you're trying to do.
All we know for certain is that you have some issue with using 'system'.

Try *reading* the Perl documentation on using 'system' ("perldoc -f
system" on the command line -or- visit http://www.perldoc.com/ and
search for 'system').

HTH

Jim
Hello Jim,
sorry, I thought everything is given...

Here the code:

$TtH = "\"c:/programme/apache
group/apache2/cgi-bin/tth.exe\"";
$mode = "";
@args = ($TtH, "-L -t -r -w0 $mode", "<tth_in.dat", ">tth_out.dat",
"2>tth_err.dat");
system(@args)== 0
or die "system @args failed: $?";

Here the result:

system "c:/programme/apache group/apache2/cgi-bin/tth.exe" -L -t -r
-w0 <tth_in.dat >tth_out.dat 2>tth_err.dat failed: 256 at
C:\Programme\Apache Group\Apache2\cgi-bin\wikitth.pl line 3252.

The file tth_in.dat exists, tth_out.dat does not and is not generated.
Calling the exe at command-line exactly as given in the errormsg
works.

Hope this helps to understand the problem - need more info?
Zeus
 
M

Malcolm Dew-Jones

Mr. Zeus ([email protected]) wrote:
: I am running a UseMod wiki

(caveat: I don't know UseMod wiki)

:and tried to implement some system calls
: using the perl command system(@args).

Some isp's disable the system command within perl. (Perhaps they
recompile perl to do this).

So I wonder, does the perl interpreter on your host support the system()
call at all?
 
B

Ben Morrow

Quoth (e-mail address removed) (Mr. Zeus):
Here the code:

You seem not to be using strictures; are you using warnings?

Every (yes, *every*) program you write, certainly every program you
post here, should start with

use strict;
use warnings;
$TtH = "\"c:/programme/apache
group/apache2/cgi-bin/tth.exe\"";

You would be better off using single quotes here:

my $TtH = '"c:/programme/.../tth.exe"';
$mode = "";

I take it you provide a different value for $mode in the real program?
@args = ($TtH, "-L -t -r -w0 $mode", "<tth_in.dat", ">tth_out.dat",
"2>tth_err.dat");
system(@args)== 0
or die "system @args failed: $?";

Here the result:

system "c:/programme/apache group/apache2/cgi-bin/tth.exe" -L -t -r
-w0 <tth_in.dat >tth_out.dat 2>tth_err.dat failed: 256 at
C:\Programme\Apache Group\Apache2\cgi-bin\wikitth.pl line 3252.

The code is essential to finding this problem: the problem is with how
you have called system.

system LIST does not use the command shell, it invokes the program
directly. Three consequences of this are

1. Stdio redirections (<, >, >>, | &c.) will not work: they are
performed by the shell.

2. Every argument must be provided as a separate item in the list. qw//
is often useful for this, I find, as is the idiom

my @args = (
-L =>
-r =>
-w => 0,
$mode
);

3. Arguments and commands with spaces in them do not need quoting. Perl
will provide the arguments given directly to execvp(2); under Unix and
other OSen with C-compatible argument passing conventions, this will
pass them straight into the program with no interpolation at all; under
Win32 the C RTL will (theoretically) deal with quoting each argument
such that the receiving program parses the command line correctly.

So, your system command was equivalent to typing

"\"c:/.../tth.exe\"" "-L -t -r -w0 " "<tth_in.dat" ">tth_out.dat" ...

into cmd.exe. Unsurprisingly, this didn't work. You have two options:

1. If you are using perl 5.8, you could try pretending you're on Unix
and doing a fork/exec pair, redirecting STD{IN,OUT,ERR} after the fork
and passing exec a list of (unquoted) arguments. This may, if you're
lucky, work... it will also be portable to Unixen, if you care about
that. This *should* keep the benefits of system/exec LIST, namely that
you don't need to worry about shell metachars in your arguments.

2. Use system STRING instead; in this case you want to keep $Tth as it
is but call system like

system "$Tth -L -t -r -w0 $mode <tth_in.dat >tth_out.dat ...";

i.e. with one string correctly quoted as you would type it into cmd.exe.
This string will be passed to cmd /c, which will then do the
redirections for you and will also require the quotes around the exe
name. This has the potential problem that if (say) $mode contains any
shell metachars (and what cmd.exe's metechars are is rather hard to say;
certainly "\%><|, possibly ^, perhaps others; the only thing you really
know is safe is /\w/) you will have to deal with quoting them in a way
cmd.exe finds acceptable yourself. You may also find you need to use
back- instead of forward-slashes for paths: cmd.exe is about the only
part of windows that cares which you use (which is why it's best to use
/ in general, as perl prefers it), but I really don't know if it works
to invoke an exe with a forward-slashed path.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top