Is it possible to get an `errorlevel 1` from `xcopy` in Windows 10?












4















Microsoft documentation states that the xcopy exit codes are



Exit code   Description
0 Files were copied without error.
1 No files were found to copy.
2 The user pressed CTRL+C to terminate xcopy.
4 Initialization error occurred.
There is not enough memory or disk space,
or you entered an invalid drive name
or invalid syntax on the command line.
5 Disk write error occurred.


I'm running a Windows 10 64bit system (spanish locale), and I've tried everything I could think of to get an errorlevel 1 from xcopy, but I've not been able. And by everything I mean the only thing I did not test was /N with long file names in a source where short names are not enabled (in my environment I can not test it). The usual suspects non matching wildcards, non present file names, empty folders, /D, /EXCLUDE, /A, /M, /U, ... were tested.



I though it should be easy (not files found?, easy), but I was wrong, it was not, so I debugged xcopy.exe and this is what I saw:




  • xcopy internally uses a method called DisplayMessageAndExit(messageID, WSTRING, exitCode) to, well, display a message and exit. It also uses several exit calls to leave the program in some cases (ex. Ctrl-C)


  • I have not found any exit call that could use a value of 1


  • From the list of calls made to DisplayMessageAndExit, none of them pass/receive a value of 1 as exit code.


  • From the list of calls made to DisplayMessageAndExit only one of them use the MessageID 0x5622 (in my install the resources associated are in C:WindowsSystem32es-ESulib.dll.mui, it is locale dependent), that is No se encuentra el archivo: %1 (File not found - %1), and the exit code used in the call is 4



Maybe there is a way in which xcopy is able to generate the 1 exit code, but I don't know how.



So the question is: Is there a way to get errorlevel 1 exit code from xcopy? What am I missing?










share|improve this question

























  • I would expect it if you use /d and no files are newer.

    – AFH
    Feb 18 '17 at 11:58











  • @AFH Nope. /d doesn't do it.

    – DavidPostill
    Feb 18 '17 at 13:04











  • @DavidPostill - Sorry, I didn't have time to check. I did say I would expect it, and I feel it should.

    – AFH
    Feb 18 '17 at 13:07






  • 2





    I guess that they in Microsoft know it. There is a sample COPYIT.BAT at the provided link to perform xcopy operations and use the batch if command to process the exit code if an error occurs. The batch does not care about errorlevel 1 at all and processes only errolevels 4, 2 and 0 (it's not a bug, it's a feature?)

    – JosefZ
    Apr 6 '17 at 7:20








  • 2





    @JosefZ, to skip :lowmemory you only need a goto, not a if errorlevel 0 that in this scenario is always true. Why to use an if? It is just my opinion, but for me it seems a (wrong) fallthrough, as in C switch statement. Of course I don't know "why" and I could be wrong (again). In any case, yes, your point creates a suspicious omission in their code.

    – MC ND
    Apr 6 '17 at 10:48
















4















Microsoft documentation states that the xcopy exit codes are



Exit code   Description
0 Files were copied without error.
1 No files were found to copy.
2 The user pressed CTRL+C to terminate xcopy.
4 Initialization error occurred.
There is not enough memory or disk space,
or you entered an invalid drive name
or invalid syntax on the command line.
5 Disk write error occurred.


I'm running a Windows 10 64bit system (spanish locale), and I've tried everything I could think of to get an errorlevel 1 from xcopy, but I've not been able. And by everything I mean the only thing I did not test was /N with long file names in a source where short names are not enabled (in my environment I can not test it). The usual suspects non matching wildcards, non present file names, empty folders, /D, /EXCLUDE, /A, /M, /U, ... were tested.



I though it should be easy (not files found?, easy), but I was wrong, it was not, so I debugged xcopy.exe and this is what I saw:




  • xcopy internally uses a method called DisplayMessageAndExit(messageID, WSTRING, exitCode) to, well, display a message and exit. It also uses several exit calls to leave the program in some cases (ex. Ctrl-C)


  • I have not found any exit call that could use a value of 1


  • From the list of calls made to DisplayMessageAndExit, none of them pass/receive a value of 1 as exit code.


  • From the list of calls made to DisplayMessageAndExit only one of them use the MessageID 0x5622 (in my install the resources associated are in C:WindowsSystem32es-ESulib.dll.mui, it is locale dependent), that is No se encuentra el archivo: %1 (File not found - %1), and the exit code used in the call is 4



Maybe there is a way in which xcopy is able to generate the 1 exit code, but I don't know how.



So the question is: Is there a way to get errorlevel 1 exit code from xcopy? What am I missing?










share|improve this question

























  • I would expect it if you use /d and no files are newer.

    – AFH
    Feb 18 '17 at 11:58











  • @AFH Nope. /d doesn't do it.

    – DavidPostill
    Feb 18 '17 at 13:04











  • @DavidPostill - Sorry, I didn't have time to check. I did say I would expect it, and I feel it should.

    – AFH
    Feb 18 '17 at 13:07






  • 2





    I guess that they in Microsoft know it. There is a sample COPYIT.BAT at the provided link to perform xcopy operations and use the batch if command to process the exit code if an error occurs. The batch does not care about errorlevel 1 at all and processes only errolevels 4, 2 and 0 (it's not a bug, it's a feature?)

    – JosefZ
    Apr 6 '17 at 7:20








  • 2





    @JosefZ, to skip :lowmemory you only need a goto, not a if errorlevel 0 that in this scenario is always true. Why to use an if? It is just my opinion, but for me it seems a (wrong) fallthrough, as in C switch statement. Of course I don't know "why" and I could be wrong (again). In any case, yes, your point creates a suspicious omission in their code.

    – MC ND
    Apr 6 '17 at 10:48














4












4








4


2






Microsoft documentation states that the xcopy exit codes are



Exit code   Description
0 Files were copied without error.
1 No files were found to copy.
2 The user pressed CTRL+C to terminate xcopy.
4 Initialization error occurred.
There is not enough memory or disk space,
or you entered an invalid drive name
or invalid syntax on the command line.
5 Disk write error occurred.


I'm running a Windows 10 64bit system (spanish locale), and I've tried everything I could think of to get an errorlevel 1 from xcopy, but I've not been able. And by everything I mean the only thing I did not test was /N with long file names in a source where short names are not enabled (in my environment I can not test it). The usual suspects non matching wildcards, non present file names, empty folders, /D, /EXCLUDE, /A, /M, /U, ... were tested.



I though it should be easy (not files found?, easy), but I was wrong, it was not, so I debugged xcopy.exe and this is what I saw:




  • xcopy internally uses a method called DisplayMessageAndExit(messageID, WSTRING, exitCode) to, well, display a message and exit. It also uses several exit calls to leave the program in some cases (ex. Ctrl-C)


  • I have not found any exit call that could use a value of 1


  • From the list of calls made to DisplayMessageAndExit, none of them pass/receive a value of 1 as exit code.


  • From the list of calls made to DisplayMessageAndExit only one of them use the MessageID 0x5622 (in my install the resources associated are in C:WindowsSystem32es-ESulib.dll.mui, it is locale dependent), that is No se encuentra el archivo: %1 (File not found - %1), and the exit code used in the call is 4



Maybe there is a way in which xcopy is able to generate the 1 exit code, but I don't know how.



So the question is: Is there a way to get errorlevel 1 exit code from xcopy? What am I missing?










share|improve this question
















Microsoft documentation states that the xcopy exit codes are



Exit code   Description
0 Files were copied without error.
1 No files were found to copy.
2 The user pressed CTRL+C to terminate xcopy.
4 Initialization error occurred.
There is not enough memory or disk space,
or you entered an invalid drive name
or invalid syntax on the command line.
5 Disk write error occurred.


I'm running a Windows 10 64bit system (spanish locale), and I've tried everything I could think of to get an errorlevel 1 from xcopy, but I've not been able. And by everything I mean the only thing I did not test was /N with long file names in a source where short names are not enabled (in my environment I can not test it). The usual suspects non matching wildcards, non present file names, empty folders, /D, /EXCLUDE, /A, /M, /U, ... were tested.



I though it should be easy (not files found?, easy), but I was wrong, it was not, so I debugged xcopy.exe and this is what I saw:




  • xcopy internally uses a method called DisplayMessageAndExit(messageID, WSTRING, exitCode) to, well, display a message and exit. It also uses several exit calls to leave the program in some cases (ex. Ctrl-C)


  • I have not found any exit call that could use a value of 1


  • From the list of calls made to DisplayMessageAndExit, none of them pass/receive a value of 1 as exit code.


  • From the list of calls made to DisplayMessageAndExit only one of them use the MessageID 0x5622 (in my install the resources associated are in C:WindowsSystem32es-ESulib.dll.mui, it is locale dependent), that is No se encuentra el archivo: %1 (File not found - %1), and the exit code used in the call is 4



Maybe there is a way in which xcopy is able to generate the 1 exit code, but I don't know how.



So the question is: Is there a way to get errorlevel 1 exit code from xcopy? What am I missing?







windows windows-10 command-line batch-file xcopy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 19 '17 at 10:06







MC ND

















asked Feb 18 '17 at 11:17









MC NDMC ND

1,171613




1,171613













  • I would expect it if you use /d and no files are newer.

    – AFH
    Feb 18 '17 at 11:58











  • @AFH Nope. /d doesn't do it.

    – DavidPostill
    Feb 18 '17 at 13:04











  • @DavidPostill - Sorry, I didn't have time to check. I did say I would expect it, and I feel it should.

    – AFH
    Feb 18 '17 at 13:07






  • 2





    I guess that they in Microsoft know it. There is a sample COPYIT.BAT at the provided link to perform xcopy operations and use the batch if command to process the exit code if an error occurs. The batch does not care about errorlevel 1 at all and processes only errolevels 4, 2 and 0 (it's not a bug, it's a feature?)

    – JosefZ
    Apr 6 '17 at 7:20








  • 2





    @JosefZ, to skip :lowmemory you only need a goto, not a if errorlevel 0 that in this scenario is always true. Why to use an if? It is just my opinion, but for me it seems a (wrong) fallthrough, as in C switch statement. Of course I don't know "why" and I could be wrong (again). In any case, yes, your point creates a suspicious omission in their code.

    – MC ND
    Apr 6 '17 at 10:48



















  • I would expect it if you use /d and no files are newer.

    – AFH
    Feb 18 '17 at 11:58











  • @AFH Nope. /d doesn't do it.

    – DavidPostill
    Feb 18 '17 at 13:04











  • @DavidPostill - Sorry, I didn't have time to check. I did say I would expect it, and I feel it should.

    – AFH
    Feb 18 '17 at 13:07






  • 2





    I guess that they in Microsoft know it. There is a sample COPYIT.BAT at the provided link to perform xcopy operations and use the batch if command to process the exit code if an error occurs. The batch does not care about errorlevel 1 at all and processes only errolevels 4, 2 and 0 (it's not a bug, it's a feature?)

    – JosefZ
    Apr 6 '17 at 7:20








  • 2





    @JosefZ, to skip :lowmemory you only need a goto, not a if errorlevel 0 that in this scenario is always true. Why to use an if? It is just my opinion, but for me it seems a (wrong) fallthrough, as in C switch statement. Of course I don't know "why" and I could be wrong (again). In any case, yes, your point creates a suspicious omission in their code.

    – MC ND
    Apr 6 '17 at 10:48

















I would expect it if you use /d and no files are newer.

– AFH
Feb 18 '17 at 11:58





I would expect it if you use /d and no files are newer.

– AFH
Feb 18 '17 at 11:58













@AFH Nope. /d doesn't do it.

– DavidPostill
Feb 18 '17 at 13:04





@AFH Nope. /d doesn't do it.

– DavidPostill
Feb 18 '17 at 13:04













@DavidPostill - Sorry, I didn't have time to check. I did say I would expect it, and I feel it should.

– AFH
Feb 18 '17 at 13:07





@DavidPostill - Sorry, I didn't have time to check. I did say I would expect it, and I feel it should.

– AFH
Feb 18 '17 at 13:07




2




2





I guess that they in Microsoft know it. There is a sample COPYIT.BAT at the provided link to perform xcopy operations and use the batch if command to process the exit code if an error occurs. The batch does not care about errorlevel 1 at all and processes only errolevels 4, 2 and 0 (it's not a bug, it's a feature?)

– JosefZ
Apr 6 '17 at 7:20







I guess that they in Microsoft know it. There is a sample COPYIT.BAT at the provided link to perform xcopy operations and use the batch if command to process the exit code if an error occurs. The batch does not care about errorlevel 1 at all and processes only errolevels 4, 2 and 0 (it's not a bug, it's a feature?)

– JosefZ
Apr 6 '17 at 7:20






2




2





@JosefZ, to skip :lowmemory you only need a goto, not a if errorlevel 0 that in this scenario is always true. Why to use an if? It is just my opinion, but for me it seems a (wrong) fallthrough, as in C switch statement. Of course I don't know "why" and I could be wrong (again). In any case, yes, your point creates a suspicious omission in their code.

– MC ND
Apr 6 '17 at 10:48





@JosefZ, to skip :lowmemory you only need a goto, not a if errorlevel 0 that in this scenario is always true. Why to use an if? It is just my opinion, but for me it seems a (wrong) fallthrough, as in C switch statement. Of course I don't know "why" and I could be wrong (again). In any case, yes, your point creates a suspicious omission in their code.

– MC ND
Apr 6 '17 at 10:48










1 Answer
1






active

oldest

votes


















0














The only thing I can think of is some sort of race condition that between xcopy gathering the list of files it will copy and actually doing the copy, some other process deletes or moves the files.



If you can get an error 1 if only SOME of the source files were missing then it might be able to do this on purpose.
About the only way I can think to do this on purpose is to have 2 or more separate processes running, one xcopy and one delete or move command, all operating on the same source files. You will need a source with lots of files in them to give the competing processes time to overtake each other.




  1. start a move, del, or robocopy /mov command on a folder with lots of files in it.

  2. in another window, and well before the first command finishes start your xcopy command


Omitting the /C switch may mean that if it is the first file xcopy tries and fails on it will give up straight away without copying any files, thus satisfying the condition of NO files copied.






share|improve this answer



















  • 1





    Good try, but no. To avoid having to wait for a collision I directly put a break point in the xcopy program just before the file copy operation and when it is reached I deleted the file to be copied. When resuming the xcopy executable I get error code 4.

    – MC ND
    Mar 14 '18 at 15:24











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1180180%2fis-it-possible-to-get-an-errorlevel-1-from-xcopy-in-windows-10%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The only thing I can think of is some sort of race condition that between xcopy gathering the list of files it will copy and actually doing the copy, some other process deletes or moves the files.



If you can get an error 1 if only SOME of the source files were missing then it might be able to do this on purpose.
About the only way I can think to do this on purpose is to have 2 or more separate processes running, one xcopy and one delete or move command, all operating on the same source files. You will need a source with lots of files in them to give the competing processes time to overtake each other.




  1. start a move, del, or robocopy /mov command on a folder with lots of files in it.

  2. in another window, and well before the first command finishes start your xcopy command


Omitting the /C switch may mean that if it is the first file xcopy tries and fails on it will give up straight away without copying any files, thus satisfying the condition of NO files copied.






share|improve this answer



















  • 1





    Good try, but no. To avoid having to wait for a collision I directly put a break point in the xcopy program just before the file copy operation and when it is reached I deleted the file to be copied. When resuming the xcopy executable I get error code 4.

    – MC ND
    Mar 14 '18 at 15:24
















0














The only thing I can think of is some sort of race condition that between xcopy gathering the list of files it will copy and actually doing the copy, some other process deletes or moves the files.



If you can get an error 1 if only SOME of the source files were missing then it might be able to do this on purpose.
About the only way I can think to do this on purpose is to have 2 or more separate processes running, one xcopy and one delete or move command, all operating on the same source files. You will need a source with lots of files in them to give the competing processes time to overtake each other.




  1. start a move, del, or robocopy /mov command on a folder with lots of files in it.

  2. in another window, and well before the first command finishes start your xcopy command


Omitting the /C switch may mean that if it is the first file xcopy tries and fails on it will give up straight away without copying any files, thus satisfying the condition of NO files copied.






share|improve this answer



















  • 1





    Good try, but no. To avoid having to wait for a collision I directly put a break point in the xcopy program just before the file copy operation and when it is reached I deleted the file to be copied. When resuming the xcopy executable I get error code 4.

    – MC ND
    Mar 14 '18 at 15:24














0












0








0







The only thing I can think of is some sort of race condition that between xcopy gathering the list of files it will copy and actually doing the copy, some other process deletes or moves the files.



If you can get an error 1 if only SOME of the source files were missing then it might be able to do this on purpose.
About the only way I can think to do this on purpose is to have 2 or more separate processes running, one xcopy and one delete or move command, all operating on the same source files. You will need a source with lots of files in them to give the competing processes time to overtake each other.




  1. start a move, del, or robocopy /mov command on a folder with lots of files in it.

  2. in another window, and well before the first command finishes start your xcopy command


Omitting the /C switch may mean that if it is the first file xcopy tries and fails on it will give up straight away without copying any files, thus satisfying the condition of NO files copied.






share|improve this answer













The only thing I can think of is some sort of race condition that between xcopy gathering the list of files it will copy and actually doing the copy, some other process deletes or moves the files.



If you can get an error 1 if only SOME of the source files were missing then it might be able to do this on purpose.
About the only way I can think to do this on purpose is to have 2 or more separate processes running, one xcopy and one delete or move command, all operating on the same source files. You will need a source with lots of files in them to give the competing processes time to overtake each other.




  1. start a move, del, or robocopy /mov command on a folder with lots of files in it.

  2. in another window, and well before the first command finishes start your xcopy command


Omitting the /C switch may mean that if it is the first file xcopy tries and fails on it will give up straight away without copying any files, thus satisfying the condition of NO files copied.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 14 '18 at 12:21









BeowulfNode42BeowulfNode42

1,43411219




1,43411219








  • 1





    Good try, but no. To avoid having to wait for a collision I directly put a break point in the xcopy program just before the file copy operation and when it is reached I deleted the file to be copied. When resuming the xcopy executable I get error code 4.

    – MC ND
    Mar 14 '18 at 15:24














  • 1





    Good try, but no. To avoid having to wait for a collision I directly put a break point in the xcopy program just before the file copy operation and when it is reached I deleted the file to be copied. When resuming the xcopy executable I get error code 4.

    – MC ND
    Mar 14 '18 at 15:24








1




1





Good try, but no. To avoid having to wait for a collision I directly put a break point in the xcopy program just before the file copy operation and when it is reached I deleted the file to be copied. When resuming the xcopy executable I get error code 4.

– MC ND
Mar 14 '18 at 15:24





Good try, but no. To avoid having to wait for a collision I directly put a break point in the xcopy program just before the file copy operation and when it is reached I deleted the file to be copied. When resuming the xcopy executable I get error code 4.

– MC ND
Mar 14 '18 at 15:24


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1180180%2fis-it-possible-to-get-an-errorlevel-1-from-xcopy-in-windows-10%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Mouse cursor on multiple screens with different PPI

Agildo Ribeiro

Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”