Error returned on Unix 'mv' system call.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Cummings
    New Member
    • Jan 2007
    • 2

    Error returned on Unix 'mv' system call.

    I am migrating an Oracle 9i to Oracle 10g database, and Perl 5.0.4 to Perl 5.8.7 in Sun Solaris environment.

    Using Perl 5.8.7, the following legacy code segment is returning a '-1' return code on the system call to execute the 'mv' command. Note that the mv request is across directories.

    sub move_inproc
    {
    print "sub move_inproc\n";
    `mv $histhome/dat/inbound/$filename $histhome/dat/inproc/$filename`;
    if ($? !=0)
    {
    &fatal_error ("913", "ERROR - Cant Move $histhome/dat/inbound/$filename to $histhome/dat/inproc");
    }
    else
    {
    &log_msg("00 0", "File $filename successfully moved to $histhome/dat/inproc dir");
    }

    Interestingly, when the code executes the fatal_error routine the Perl rename function works fine (also across directories).

    sub fatal_error
    {
    ...
    rename ("$histhome/dat/inproc/$filename", "$histhome/dat/inbad/$filename");
    if ($? !=0)
    {
    &log_msg ("523", "WARNING - Cant Move $histhome/dat/inproc/$filename to $histhome/dat/inbad");
    }
    else
    {
    &log_msg("00 0", "File $filename moved to $histhome/dat/inbad dir"); ...
    }

    I can find no reason why the system call to the 'mv' command fails, and the Perl 'rename' function works, and better yet, why the 'mv' system call is used in one sub-module, and the Perl 'rename' function in another sub-module.

    I am planning on replacing the 'mv' system call with the Perl 'rename' function, unless of course you experts out there tell me different.

    Comments welcome; thanks,
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Instead of the system mv command, you should instead use File::Copy qw(move).



    The primary reason for this is because this will allow you to get meaningful error messages whenever something goes wrong. Same is true of the rename function. Just look in $! for the error cause.

    Comment

    • Mark Cummings
      New Member
      • Jan 2007
      • 2

      #3
      thanks.

      I figured out the $! return variable, and have tested okay using the rename with meaningful results.

      Comment

      Working...