You are currently offline, waiting for your internet to reconnect
Questions about Windows 10? Click here

PRB: XP_CMDSHELL Does Not Work with XCOPY

This article was previously published under Q152134
This article has been archived. It is offered "as is" and will no longer be updated.
Symptoms
XP_CMDSHELL does not work with XCOPY. When tried, the XP_CMDSHELL alwaysreturns "0 rows affected," and files and directories are not copied. Thesame XCOPY command works fine from the command prompt.

NOTE: This problem does not occur with Microsoft SQL Server 2000.
Cause
Certain commands such as XCOPY sometimes expect input from the user.Because of this, they must be assigned an input handle. Since we do notcreate the process with an input handle assigned, it fails.
Workaround
To work around this problem you can use the COPY command instead. Or, you can also pipe the output to a NUL console. For example:
xp_cmdshell 'fc c:\test1.txt c:\test.txt <NUL:'				
-or-
xp_cmdshell 'fc c:\test1.txt c:\test.txt <NUL: >c:\output.txt'				
extended stored procedure
Properties

Article ID: 152134 - Last Review: 10/26/2013 10:23:00 - Revision: 4.0

  • Microsoft SQL Server 6.0 Standard Edition
  • Microsoft SQL Server 6.5 Standard Edition
  • Microsoft SQL Server 7.0 Standard Edition
  • kbnosurvey kbarchive KB152134
Feedback