Bug #22134 Backup/restore exit code 0 after a failure to find a file
Submitted: 9 Sep 2006 0:11 Modified: 20 Sep 2006 14:51
Reporter: Brendan McKeown Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.0, 4.1 OS:Microsoft Windows (Windows XP)
Assigned to: Iggy Galarza

[9 Sep 2006 0:11] Brendan McKeown
Description:
On Windows XP the exit code of the mysqldump and mysql utilities is 0 whenever an incorrect path is supplied. On Linux/Solaris the exit code is 1 under the same condition.

An exit code of 0 indicates the successful completion of a program on Windows/Solaris/Linux.

How to repeat:
Run this Windows batch file with "notpresent" representing a non-existent directory:

@c:\icos\mysql\bin mysqldump -u root --password=ziggy1 reporting > c:\notpresent\data.dat
@echo Return code is: %ERRORLEVEL%

The output will be:

The system cannot find the path specified.
Return code is: 0

--------------------------------------------------------------------

Run this batch file:

@c:\icos\mysql\bin\mysql -u root --password=ziggy1 reporting < c:\notpresent\data.dat
@echo Return code is: %ERRORLEVEL%

The output will be:

The system cannot find the path specified.
Return code is: 0

---------------------------------------------------------------------

An exit code of 1 is returned when the same test is run on Linux/Solaris using a shell script.

Suggested fix:
The exit code should be something other than 0, perhaps 1 as is the case with a Linux/Solaris installation. This would indicate that an error has occurred.
[11 Sep 2006 15:12] Valerii Kravchuk
Thank you for a bug report. Verified just as described, also with mysqldump 10.10 from MySQL 5.0.x on Windows XP.
[20 Sep 2006 14:51] Iggy Galarza
I was able to reproduce the problem as described using the cmd.exe shell.  However, I was not able to reproduce the problem on the same machine with the same binaries using the CygWin bash shell.  To be certain that this behaviour had nothing to do with MySQL, I wrote an MFC32 command-line application(return_el.exe) that always returns an ERRORLEVEL of 1 and was able to reproduce the problem with cmd.exe.  As you can see from this comparison, when using cmd.exe and syntax like "command" > "Not Present File", the ERRORLEVEL equals 0 regardless of the ERRORLEVEL set by the "command".

cmd.exe shell
C:\src\return_el\Debug>echo %ERRORLEVEL%
0

C:\src\return_el\Debug>return_el.exe

C:\src\return_el\Debug>echo %ERRORLEVEL%
1

C:\src\return_el\Debug>.\return_el.exe > c:\notpresent\data.dat
The system cannot find the path specified.

C:\src\return_el\Debug>echo %ERRORLEVEL%
0

CygWin Shell

iggy@Area51 /cygdrive/c/src/return_el/Debug
$ echo $?
0

iggy@Area51 /cygdrive/c/src/return_el/Debug
$ ./return_el.exe

iggy@Area51 /cygdrive/c/src/return_el/Debug
$ echo $?
1

iggy@Area51 /cygdrive/c/src/return_el/Debug
$ echo $?
0

iggy@Area51 /cygdrive/c/src/return_el/Debug
$ ./return_el.exe > c:/notpresent/data.dat
bash: c:/notpresent/data.dat: No such file or directory

iggy@Area51 /cygdrive/c/src/return_el/Debug
$ echo $?
1