Microsoft KB Archive/281340

= PRB: File Compare Utility Fails to Run from Xp_cmdshell =

Article ID: 281340

Article Last Modified on 8/15/2002

-

APPLIES TO


 * Microsoft SQL Server 7.0 Standard Edition

-



This article was previously published under Q281340



SYMPTOMS
The file compare utility fails to run from the xp_cmdshell extended stored procedure.



CAUSE
The SQL Server process does not create a WinStation for the fc command. If you pipe the output to a Nul console, you get the results you expect.



WORKAROUND
To work around this problem you can either:   Pipe the output to a NUL console. For example: xp_cmdshell 'fc c:\test1.txt c:\test.txt c:\output.txt' -or-

 Create a SQL Server Agent job of type &quot;Operating System Command&quot; and direct the output to a file. Then, call the job from the Query Analyzer with the sp_start_job stored procedure.



MORE INFORMATION
To see the failure occur, use the following steps:

 Create two files named test1 and test and make sure that the files have data in them.  Log in as system administrator (sa) to the SQL Server server, and then execute the following query from Query Analyzer: xp_cmdshell 'fc c:\test1.txt c:\test.txt'

-or-

xp_cmdshell 'fc c:\test1.txt c:\test.txt > c:\output.txt' These steps return a &quot;null&quot; as the result and no error occurs. The xp_cmdshell extended stored procedure executes correctly for other DOS commands. </li></ol>

If you use the following example from SQL Server 2000 Books Online DECLARE @result int

EXEC @result = xp_cmdshell 'fc c:\test1.txt c:\test.txt'

IF (@result = 0)

PRINT 'Success'

ELSE

PRINT 'Failure' the result is Failure, which indicates that the file compare does not work from within xp_cmdshell.

A similar problem might occur if you use the XCOPY utility in an xp_cmdshell extended stored procedure.

Additional query words: xp_cmdshell file compare fc utility xcopy

Keywords: kbprb KB281340

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.