Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

carriage return/line feed in DOS through xp_cmdshell

Status
Not open for further replies.

ruupy

Programmer
Jan 12, 2001
29
NL
Hellow you all,

An interesting difference between dos en SQL has come to my attention....

A carriage return/linefeed in SQL is realised by 'char(13) char(10)...if u'd like to realise a CR/LF in DOS using xp_cmdshell, the story changes:

The char(x) is of no use, u'll have to use '&' to indicate a CR/LF.

At a DOSprompt the following works fine:

'C:>echo line1 &echo line2'

Results is :

line1
line2

Using xp-cmdshell, the following also works fine:

exec master .. xp_cmdshell 'echo line1 &echo line2'

...HOWEVER....

exec master .. xp_cmdshell 'echo line1 &echo line2 >> C:\test.txt'

does NOT work!,....only 'line2' is written to the textfile.
'Line1' appears (if 'NO_OUTPUT' is not present) as SQL output....

Does anyone know how i should put togehter the exec code line in order to get both lines with a CR/LF written to the text file???


Please ask me if the text is a bit too vague

ThenX in @vance
RuupY
 
You could try this:

exec master .. xp_cmdshell 'echo line1 >> C:\test.txt&echo line2 >> C:\test.txt'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top