Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perls system() call fails in a cgi-file running on win2k and apache

Reply
Thread Tools

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

 
 
Mr. Zeus
Guest
Posts: n/a
 
      10-12-2004
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
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-12-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Mr. Zeus) wrote in
news:(E-Mail Removed) om:

> 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.
 
Reply With Quote
 
 
 
 
James Willmore
Guest
Posts: n/a
 
      10-12-2004
Mr. Zeus wrote:
> 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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-12-2004
Mr. Zeus <(E-Mail Removed)> wrote:


> Are there additional mods necessary in the apache config?



There is no Perl content in that question.


> What to do exactly?



Ask server configuration questions in a newsgroup about server configuration.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Mr. Zeus
Guest
Posts: n/a
 
      10-13-2004
James Willmore <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Mr. Zeus wrote:
> > 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

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
 
Reply With Quote
 
Malcolm Dew-Jones
Guest
Posts: n/a
 
      10-13-2004
Mr. Zeus ((E-Mail Removed)) 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?
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      10-13-2004

Quoth (E-Mail 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

--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
(E-Mail Removed) Groucho Marx
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Text File Encoding and converting to Perls internal UTF-8 encoding sln@netherlands.com Perl Misc 2 04-17-2009 11:22 PM
using target words from arrays in regex, pythons version of perls'map' Lance Hoffmeyer Python 6 05-17-2006 03:04 AM
HTML parsing as good as Perls. TLOlczyk Ruby 5 06-21-2005 09:18 PM
NEWBIE: Perls System -command and Cygwin bash-shell Pekka Niiranen Perl Misc 7 07-25-2004 09:47 AM
Emulate perls local Karsten Meier Ruby 2 09-09-2003 07:54 PM



Advertisments