system call problem under Win32

U

Uwe Huniar

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
 
M

Mothra

Uwe said:
- 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
 
X

xhoster

Uwe Huniar said:
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
 
U

Uwe Huniar

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


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).

--

--------------------------------------------------------------------
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: (e-mail address removed)
(e-mail address removed)
(e-mail address removed)-karlsruhe.de
 
D

Dave

Uwe Huniar said:
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





--

--------------------------------------------------------------------
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: (e-mail address removed)
(e-mail address removed)
(e-mail address removed)-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.
 

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,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top