Verify scp return status

Hi all

below is a snippet of my perl code

system ("scp -pq  $dest_file $path");

How i can i trap the return status? ie if the scp fails how can i know ?

From the perl 5.8 man page:

 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".  This is not what you want to use to
             capture the output from a command, for that you
             should use merely backticks or "qx//", as described
             in "`STRING`" in perlop.  Return value of -1
             indicates a failure to start the program (inspect $!
             for the reason).

             Like "exec", "system" allows you to lie to a program
             about its name if you use the "system PROGRAM LIST"
             syntax.  Again, see "exec".

             Because "system" and backticks block "SIGINT" and
             "SIGQUIT", killing the program they're running
             doesn't actually interrupt your program.

                 @args = ("command", "arg1", "arg2");
                 system(@args) == 0
                      or die "system @args failed: $?"

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

                 $exit_value  = $? >> 8;
                 $signal_num  = $? & 127;
                 $dumped_core = $? & 128;

             or more portably by using the W*() calls of the
             POSIX extension; see perlport for more information.

Check the perlfunc man page for more details. The perlfunc man page can be accessed by setting the MANPATH to include the "<perl_install_dir>/man" directory.

Hi,
does it mean i should do a

 if ($? = -1) print $! ;# to output error message
else print "success"

I tried the above and got something like " $! = inappropriate ioctl for device".
did i use $? wrongly?

Hi blowtorch, i amended my code, and it worked.thanks a lot

$exit_value  = $? >> 8;
if ($exit_value != 0) 
	{print "Sending of file NO\n";}
	else 
	{print "Sending of file DONE\n";}