system call problem under Win32

Discussion in 'Perl Misc' started by Uwe Huniar, May 31, 2006.

  1. Uwe Huniar

    Uwe Huniar Guest

    I have a strange error with the combination of perl, java and Windows...

    What we do:

    - a java program calls (with runtime.exec) 'perl PATH/script.pl'

    - in script.pl there are several system calls to binaries

    - system "prog.exe >> out";

    java and perl work as expected, the script.pl runs on the shell
    (cmd.exe as well as bash with cygwin) without problems.
    But the script.pl does not do the system call at all, it passes the
    system " ... "; without executing the binary (also a simple echo or
    'del file' does not work).

    Error on:
    Windows 2000, ActivePerl 5.8.8, Java2 1.5.0
    Windows XP, ActivePerl 5.8.8, Java2 1.5.0
    Windows XP, PXPerl 5.8.7-6, Java2 1.5.0

    Works properly on:
    Windows XP, cygwin perl 5.8.7, Java2 1.5.0

    Anyone any idea how to circumvent that?

    Uwe
    Uwe Huniar, May 31, 2006
    #1
    1. Advertising

  2. Uwe Huniar

    Mothra Guest

    Uwe Huniar wrote:
    > - system "prog.exe >> out";
    >


    Shame on you for not checking the return status of your system calls
    From the docs:

    You can check all the failure possibilities by inspecting $?
    like this:

    if ($? == -1) {
    print "failed to execute: $!\n";
    }
    elsif ($? & 127) {
    printf "child died with signal %d, %s coredump\n",
    ($? & 127), ($? & 128) ? 'with' : 'without';
    }
    else {
    printf "child exited with value %d\n", $? >> 8;
    }

    Hope this helps

    Mothra
    Mothra, May 31, 2006
    #2
    1. Advertising

  3. Uwe Huniar

    Guest

    Uwe Huniar <-karlsruhe.de> wrote:
    > I have a strange error with the combination of perl, java and Windows...
    >
    > What we do:
    >
    > - a java program calls (with runtime.exec) 'perl PATH/script.pl'
    >
    > - in script.pl there are several system calls to binaries
    >
    > - system "prog.exe >> out";


    I have a radical idea. If you want to know why the "system" failed, why
    not check to see why the "system" failed?


    The return value is the exit status of the program
    as returned by the "wait" call. To get the actual
    exit value shift right by eight (see below). See
    also "exec". ...
    Return value
    of -1 indicates a failure to start the program
    (inspect $! for the reason).



    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , May 31, 2006
    #3
  4. Uwe Huniar

    Uwe Huniar Guest

    Thanks for the nice answer, I have indeed forgotten to mention
    that the return value tells me that the file or directory has
    not been found.

    The problem is that even if I give the full path to the executable
    (and, as I told even a shell intrinsic like del or dir, and also
    cmd.exe with full path) does not help. And, of course, I do a

    if (-x $exec ) ... else die(...);
    system "$exec >> $output";
    print "exited with $? \n $! \n";

    So the problem is that obviously it does not matter what I call with
    'system', it seems that system itself does not run.

    I am not a perl expert (unfortunately I am not a Windows or Java or
    perl expert, but using the combination...) but my guess is that perl
    tries to start some kind of a shell to start the given binary within
    that shell. Seems that perl does not find the shell itself and thus
    the return value is not related to the argument of sytem but to sytem
    itself. Is that reasonable?

    Since the perl script runs without problems when started from the
    command line, it has something to do with the combination of
    Java and perl. The only possible problem I know is the fact that
    Java does not export all environment variables... but that is why
    I set $ENV{PATH} 'by hand' at the beginning of the script (but it
    does not make any difference if I do that or not).

    Any help is welcome,

    Uwe


    wrote:
    > Uwe Huniar <-karlsruhe.de> wrote:
    >> I have a strange error with the combination of perl, java and Windows...
    >>
    >> What we do:
    >>
    >> - a java program calls (with runtime.exec) 'perl PATH/script.pl'
    >>
    >> - in script.pl there are several system calls to binaries
    >>
    >> - system "prog.exe >> out";


    > I have a radical idea. If you want to know why the "system" failed, why
    > not check to see why the "system" failed?



    > The return value is the exit status of the program
    > as returned by the "wait" call. To get the actual
    > exit value shift right by eight (see below). See
    > also "exec". ...
    > Return value
    > of -1 indicates a failure to start the program
    > (inspect $! for the reason).




    > Xho


    > --
    > -------------------- http://NewsReader.Com/ --------------------
    > Usenet Newsgroup Service $9.95/Month 30GB


    --

    --------------------------------------------------------------------
    Uwe Huniar |
    COSMOlogic GmbH&Co.KG | Institut f. physikalische Chemie
    Burscheider Str. 515 | Lehrstuhl fuer theoretische Chemie
    D-51381 Leverkusen | Universitaet Karlsruhe
    Germany | Kaiserstrasse 12
    | D-76128 Karlsruhe / Germany
    | Tel.: +49(0)721-608-2924
    | Fax.: +49(0)721-608-7225
    EMail:

    -karlsruhe.de
    Uwe Huniar, Jun 1, 2006
    #4
  5. Uwe Huniar

    Dave Guest

    "Uwe Huniar" <-karlsruhe.de> wrote in message
    news:e5mba4$mlj$-karlsruhe.de...
    > Thanks for the nice answer, I have indeed forgotten to mention
    > that the return value tells me that the file or directory has
    > not been found.
    >
    > The problem is that even if I give the full path to the executable
    > (and, as I told even a shell intrinsic like del or dir, and also
    > cmd.exe with full path) does not help. And, of course, I do a
    >
    > if (-x $exec ) ... else die(...);
    > system "$exec >> $output";
    > print "exited with $? \n $! \n";
    >
    > So the problem is that obviously it does not matter what I call with
    > 'system', it seems that system itself does not run.
    >
    > I am not a perl expert (unfortunately I am not a Windows or Java or
    > perl expert, but using the combination...) but my guess is that perl
    > tries to start some kind of a shell to start the given binary within
    > that shell. Seems that perl does not find the shell itself and thus
    > the return value is not related to the argument of sytem but to sytem
    > itself. Is that reasonable?
    >
    > Since the perl script runs without problems when started from the
    > command line, it has something to do with the combination of
    > Java and perl. The only possible problem I know is the fact that
    > Java does not export all environment variables... but that is why
    > I set $ENV{PATH} 'by hand' at the beginning of the script (but it
    > does not make any difference if I do that or not).
    >
    > Any help is welcome,
    >
    > Uwe
    >
    >
    > wrote:
    >> Uwe Huniar <-karlsruhe.de> wrote:
    >>> I have a strange error with the combination of perl, java and Windows...
    >>>
    >>> What we do:
    >>>
    >>> - a java program calls (with runtime.exec) 'perl PATH/script.pl'
    >>>
    >>> - in script.pl there are several system calls to binaries
    >>>
    >>> - system "prog.exe >> out";

    >
    >> I have a radical idea. If you want to know why the "system" failed, why
    >> not check to see why the "system" failed?

    >
    >
    >> The return value is the exit status of the program
    >> as returned by the "wait" call. To get the actual
    >> exit value shift right by eight (see below). See
    >> also "exec". ...
    >> Return value
    >> of -1 indicates a failure to start the program
    >> (inspect $! for the reason).

    >
    >
    >
    >> Xho

    >
    >> --
    >> -------------------- http://NewsReader.Com/ --------------------
    >> Usenet Newsgroup Service $9.95/Month 30GB

    >
    > --
    >
    > --------------------------------------------------------------------
    > Uwe Huniar |
    > COSMOlogic GmbH&Co.KG | Institut f. physikalische Chemie
    > Burscheider Str. 515 | Lehrstuhl fuer theoretische Chemie
    > D-51381 Leverkusen | Universitaet Karlsruhe
    > Germany | Kaiserstrasse 12
    > | D-76128 Karlsruhe / Germany
    > | Tel.: +49(0)721-608-2924
    > | Fax.: +49(0)721-608-7225
    > EMail:
    >
    > -karlsruhe.de



    You will get better answers if you give us the actual code used (in a test
    run - see 'short but complete script' in the posting guidelines) and the
    actual error returned.
    Dave, Jun 1, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    0
    Views:
    399
  2. Wagner Dias
    Replies:
    3
    Views:
    3,035
    Andre Kostur
    Mar 28, 2005
  3. Replies:
    2
    Views:
    467
    Peter Hansen
    May 7, 2005
  4. Michael Satterwhite

    system call not working under cron

    Michael Satterwhite, May 6, 2009, in forum: Ruby
    Replies:
    9
    Views:
    108
    Robert Klemme
    May 7, 2009
  5. Replies:
    1
    Views:
    132
    Ian Wilson
    Jun 15, 2007
Loading...

Share This Page