PDA

View Full Version : DOSCMD recursive COPY NUL fails with exit code 104


philip
03-18-2004, 11:41 AM
I have a step in a build that does:
%DOSCMD% FOR /R D:\directory /D %%f IN (*.*) DO COPY NUL %%f\Vers_081.txt

This is intended to create a 0-byte placeholder file in each subdirectory in the path. If I run the command (without the %DOSCMD% and changing the %%f to %f) from a DOS prompt, it works correctly.

When this is run in Visual Build, it fails with an error:
Process completed with exit code 104
although it appears to create all the placeholder files correctly. If I change the "COPY NUL" to "ECHO. > ", it still fails in Visual Build with the same message and exit code (but again, it does create the files).

This is version 5.0 of Visual Build (licensed) running on Windows NT4 SP6a.

kinook
03-20-2004, 07:57 PM
I suspect that COPY is returning exitcode 104 in both scenarios, but is only being detected and aborted by VBP. You could add that code to the success codes for the Run Program step (0, 104 in the Success exit codes field).

philip
03-21-2004, 06:38 PM
I tried the same command in a batch file, with a check for the ERRORLEVEL at the end of the batch file, and the ERRORLEVEL is 0 when run in a batch file.

kinook
03-21-2004, 10:19 PM
To get an equivalent comparison with what VBP is doing when executing internal OS commands, create a .cmd script that looks like this:

cmd /c FOR /R D:\Directory /D %%f IN (*.*) DO COPY NUL %%f\Vers_081.txt
echo %ERRORLEVEL%

I'll bet that if you run this from a Command Prompt you'll get the same errorlevel/exitcode behavior as inside VBP (on Win XP, it shows an exitcode of 2012907760). The cmd /c part is necessary from within VBP since 'copy' is implemented by the command interpreter. I'm not sure why cmd.exe produces a different exitcode in this situation, but it sounds like a bug in Windows (unless there's something about the statement syntax that isn't technically valid, but then you would expect it to fail without doing anything).

kinook
04-01-2004, 09:22 AM
This seems to be a general problem when calling cmd /c FOR. One workaround is to put the FOR call in a batch file (which tests the exitcode itself and performs a no-op statement to force a 0 exitcode on success). This can be copied/pasted into VBP:



<step action='Write File' type='0'>
<Filename>%TEMP%\x.bat</Filename>
<Text><![CDATA[@FOR /R %TEMP% /D %%%%f IN (*.*) DO copy NUL "%%%%f\Vers_081.txt"
@IF %%ERRORLEVEL%% == 0 GOTO Done
@rem this executes another statement that will succeed so the callee gets a 0 exitcode
:Done]]></Text>
<description>Create a temporary batch file to perform a FOR command and ensure a 0 exitcode on success when called via cmd /c</description>
<indent type='3'>1</indent>
<name>create batch file</name>
</step>
<step action='Run Program' type='0'>
<command>%DOSCMD% call "%TEMP%\x.bat"</command>
<description>Call the temporary batch file that was created</description>
<indent type='3'>1</indent>
<name>call batch file</name>
<outputfrom type='3'>1</outputfrom>
</step>