1

I'm trying to run a .bat on SQL Server:

exec xp_cmdshell 'C:\prueba_bat.bat'

when I execute the output is:

f" >> archivo_union.txt was unexpected at this time. NULL

I want to join all the files and make only one and bluk the new file

My .bat code is

@echo off
cd C:\Users\jlroja01\Documents\Download\Servicio\

for %f in (*) do type "%f" >> new_files_united.txt

pause
exit

If I execute it from the cmd prompt, it works.

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
  • There doesn't seem to be any reason why you're using a batch file for this task, when a command is all you need. Were you to use a batch file, you could probably still do that with a single line, `@Type "C:\Users\jlroja01\Documents\Download\Servicio\*">"new_files_united.txt"`. – Compo Jan 30 '19 at 14:10

1 Answers1

0

I do not think it is a specific problem of SQL Server.

Try to replace the line

for %f in (*) do type "%f" >> new_files_united.txt

with

for %%f in (*) do type "%%f" >> new_files_united.txt

See this answer.

If I execute it from the cmd prompt, it works.

When you execute just the line

for %f in (*) do type "%f" >> new_files_united.txt

from cmd, it works. But when you execute the whole bat script, it produces the same error without exec xp_cmdshell.

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
  • I made a change in the line command but now I got the next output : 'C:\Users\jlroja01\Documents\prueba_bat.bat' is not recognized as an internal or external command, operable program or batch file. NULL – Gustavo Hernandez Cruz Jan 30 '19 at 16:34
  • This comment is probably related to @Compo 's suggestion & not to this answer...? – Vojtěch Dohnal Jan 31 '19 at 08:27