To handle the case during copy when: No space left on device

 print "After create SubDir routine.";
                  createSubDirs($fileDir);
                        my $from = $ORACLE_HOME.$dirSep.$file;
                        my $to = $bootstrapDir.$dirSep.$fileDir;
                        if ($isWindows)  {
                           copy($from, $to);
                        } else {                        
                          system("cp -rf $from $to");                           
                        }
                        print "\nCopied file $from to $to\n";

In the above code I wanted to handle the case that during copy when: No space left on device it should not keep listing error for every file to the user that: " No space left on device" either it should just gracefully come out saying the "Process Failed."

then I manipulated the code like:

             else {         
                          system("cp -rf $from $to 2>/dev/null");
                           if ($? ne 0){
                             print "Process failed."
                           }

but it seems the return code is still returning code as 0 and I still could not trap the error.

Please suggest.

The code I mentioned is the perl code .. I just missed to mention that.

Hi.

Perhaps some help from:

            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 or an
            error of the wait(2) system call (inspect $! for the reason).

            If you'd like to make "system" (and many other bits of Perl) die
            on error, have a look at the autodie pragma.

-- excerpt from perldoc -f system

Best wishes ... cheers, drl

Can you use File::Copy module ?

use File::Copy;
copy("sourcefile","destinationfile") or die "Copy failed: $!";