Microsoft KB Archive/255749

= BUG: xp_cmdshell Does Not Display Last Line of Command Output =

Article ID: 255749

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft SQL Server 6.5 Standard Edition
 * Microsoft SQL Server 7.0 Standard Edition

-



This article was previously published under Q255749



BUG #: 18996 (SQLBUG_65)

BUG #: 57628 (SQLBUG_70)



SYMPTOMS
The last line of a command's output is not returned by the built-in extended stored procedure xp_cmdshell if that line does not end in a carriage return/line feed (CR/LF).



WORKAROUND
To work around this problem, add a CR/LF to the end of the data sent to stdout by the executed command.

The following two workarounds assume that you are trying to capture the output of the following command: exec master..xp_cmdshell 'someapp.exe param1 param2'  Append a file containing CR/LF to the end of the file containing the output you want to display.  Using a text editor such as Notepad, create a file named Cr.txt. Press the ENTER key once in the text editor, then save the file.  Change the xp_cmdshell command to redirect the output of the command to a file: exec master..xp_cmdshell 'someapp.exe param1 param2 > c:\outfile.txt'   Using xp_cmdshell, append the Cr.txt file to the end of your output file: exec master..xp_cmdshell 'copy c:\outfile.txt + c:\cr.txt c:\outfile.txt'   Use the type command to display the modified output file: exec master..xp_cmdshell 'type c:\outfile.txt'  </li>  Pipe the output of your application through another simple application that appends a CR/LF to the end of the stdout stream: exec master..xp_cmdshell 'someapp.exe param1 param2 | addcrlf.exe' Below is an outline of such an application.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. int main(int argc, char* argv[]) {   int c;    while ((c = getc(stdin)) != EOF) putc (c, stdout); putc ('\n', stdout); return 0; }                       </li></ul>
 * 1) include "string.h"
 * 2) include "stdlib.h"

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

MORE INFORMATION
The built-in extended stored procedure xp_cmdshell executes a given command string as an operating-system command shell and returns any output as rows of text.

Additional query words: truncated incomplete missing end linefeed

Keywords: kbbug kbpending KB255749

-

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

© Microsoft Corporation. All rights reserved.