Thank you Peter; that does the trick.

If the backtick command works (like `pwd`;) you get
        $? = 0
        $! = No such file or directory

But if you do e.g.
        touch wibble
        chmod -r wibble

then in Perl
        `wibble` ;

you get
        $? = 256
        $! = Permission denied

I.e. when $? is non-zero $! describes what went wrong with the backtick
command, otherwise it's irrelevant. I guess when the backtick works Perl has
internally done some system call that gets $! set to "No such file.." (I got
this on 3 different platforms: NCR (SVR4), Solaris and Windows.)

Thanks again - I'd been struggling with this for ages. (And thanks to the
others who've replied as I've been typing this!)

Ron

-----Original Message-----
From: Peter Cornelius [mailto:[EMAIL PROTECTED]]
Sent: 23 May 2001 19:14
To: 'Mitchell, Ronald'; '[EMAIL PROTECTED]'
Subject: RE: $! after using backticks


>I want to check that a backtick command has executed OK. I thought I could
>do that by looking at the $! variable. 

Check $?
This is Child exit status which is what you get when you spawn another
process with back ticks.

The $! is the ERRNO (or Error string depending on context) for the last
system call.

Hope this helps,
Peter C.

Reply via email to