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

Discussion in 'Perl Misc' started by Mr. Zeus, Oct 12, 2004.

  1. Mr. Zeus

    Mr. Zeus Guest

    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
    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
    Mr. Zeus, Oct 12, 2004
    1. Advertisements

  2. (Mr. Zeus) wrote in
    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).
    Good for you.
    Find a telepath.

    A. Sinan Unur, Oct 12, 2004
    1. Advertisements

  3. 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 and
    search for 'system').


    James Willmore, Oct 12, 2004

  4. There is no Perl content in that question.

    Ask server configuration questions in a newsgroup about server configuration.
    Tad McClellan, Oct 12, 2004
  5. Mr. Zeus

    Mr. Zeus Guest

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

    Here the code:

    $TtH = "\"c:/programme/apache
    $mode = "";
    @args = ($TtH, "-L -t -r -w0 $mode", "<tth_in.dat", ">tth_out.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\ 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

    Hope this helps to understand the problem - need more info?
    Mr. Zeus, Oct 13, 2004
  6. Mr. Zeus () 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?
    Malcolm Dew-Jones, Oct 13, 2004
  7. Mr. Zeus

    Ben Morrow Guest

    Quoth (Mr. Zeus):
    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;
    You would be better off using single quotes here:

    my $TtH = '"c:/programme/.../tth.exe"';
    I take it you provide a different value for $mode in the real program?
    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,

    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 Morrow, Oct 13, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.