> -----Original Message-----
> From: Bob Green [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 23, 2002 9:11 AM
> To: [EMAIL PROTECTED]
> Subject: system() error return codes
> 
> 
> I need to execute DOS level commands from perl and I must be 
> able to test
> for success.
> I've found the system() function and it seems to work except 
> I'm having
> problems getting the correct error return back.
> 
> To test the error return I've created this very simple code.  
> In it I try
> everything I know to get the error return back with no 
> success.  The correct
> error return value for this should be a 4.  Any suggestions 
> on how I can
> execute a DOS command and get the error return back would be greatly
> appreciated.
> 
> thanks, BobG.
> 
> # errorcode.pl
> # generate an error to test the return,
> 
> use Win32;
> 
> @cmd = ("xcopy","ThisFileDoesNotExist", "foo.out" );
> 
> $return = system(@cmd);   ##### The return code for xcopy should be 4.
> 
> print "The return code for xcopy should be 4.\n";
> print "return = $return\n";
> print "? = $?\n";
> print "getlasterror = ";
> print (  Win32::GetLastError());
> print "\nFormated error = ";
> print ( Win32::FormatMessage (Win32::GetLastError()));

A trip to

   perldoc -f system

would be helpful. You'll find this:

   ...The return value is the exit status of the program as
   returned by the C<wait> call.  To get the actual exit value 
   divide by 256.

The $? variable displays the same behavior. This is documented
in

   perldoc perlvar

HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to