ginju has asked for the wisdom of the Perl Monks concerning the following question:

Hello, My perl script is trying to compile some files and errors out if the compile failed. Precisely this is what I am doing:

some perl...

system (some compile command...)
if ($? != 0)
{
warn "Compile error...\n";
}

Some more perl...

This worked fine ona unix machine. I know for a fact that the files I am to compile are good, except maybe for a couple of them. Infact all the files compile ona Solaris machine (SYSTEM V UNIX release) But when I transfer the same perl script and the files to be compiled now on the windows NT machine, for every file I geta compile error. The perl scripts were modified to be compatible with NT. In the sense that the directory listing would be a\\b\\c.. instead of a/b/c.. as in unix. other than that there is not much to this script.

please advise

Replies are listed 'Best First'.
Re: Does $? work in NT?
by rchiav (Deacon) on Apr 26, 2001 at 03:46 UTC
    There's no problem with $? that I know of.

    You know for a fact that they compile on Solaris, but are you sure that they compile under Windows? Can you compile these files without the Perl script? Have you tried to execute the same commands by hand to see what happens? this really sounds more like an issue with the porting of your source files than a perl issue..

    Rich

    ps- You can still use ../temp/my/dir type of directory notation on NT in perl.. just not in your system calls.

(tye)Re: Does $? work in NT?
by tye (Sage) on Apr 26, 2001 at 18:27 UTC

    Not all commands under Windows use reasonable exit status values.

    I suggest you generate cases that work and fail and see what values that particular compiler uses for exit values (what ends up in $?) for the different cases to see if you can figure out how to determine success or failure from $?.

            - tye (but my friends call me "Tye")
Re: Does $? work in NT?
by diarmuid (Beadle) on Apr 26, 2001 at 14:53 UTC
    If I were you I'd do a print STDOUT on the command syntax and the cwd just before I ran the compile command. Also you could try using backticks (perldoc perlop) instead of the system command just to get it up and running <bp>
    $program_output = `compile_command`; print STDOUT $program_output;