xp_cmdshell...echo... generates several files instead of 1

  • Hi,

    In a stored procedure I need to report some datas in a file. So I use  the command : EXEC master..xp_cmdshell 'echo ' + @msg + '>' + @file

    My problem is:

    If @file = 'log062304.txt', no problem. The file is in the directory 'C:\Winnt\system32'

    But I need to generate a file with a longer name and in a different directory. But if @file = 'C:\files\log_pbs_062304.txt', it creates 3 different files : 'log_pbs_062304.txt', 'log_re' and 'log_rejet_230'...

    Is it a problem with my procedure which is too fast for the xp_cmdshell ?

    Thanks!

    Oliver

     

  • I have a number of jobs which perform file operations via xp_cmdshell and have never experienced anything like this.  I would suggest that you take a long, hard look at your code.  You might try placing a space before and after the '>' symbol.

    Steve

  • It is perhaps also worth putting double quotes round the long filename.

    This has solved problems on the earlier versions of windows for me before!

    Dave.

  • Maybe you have special characters in @msg, especially ">" or "|", also "&&".

  • In fact, it happens when the length of my variable @file is more than 18 characters (for example : 'C:\log_00000015.txt').If it's less ('C:\log_0000001.txt'). , no problem. Strange...

    My file doesn't contain special character ('|' ...). And my code is fine, I think.

     

     

     

  • Can you post your code?


    Cheers,
    - Mark

  • Thanks for your help !

    My code was wrong : I have declared my variable @file as varchar and not as sysname.

     

     

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply