tags:

views:

55

answers:

1

Hello, I am trying to execute a batch file from C# code using Process class. Batch gets to parameters, passed as quoted strings into ProcessStartInfo.Arguments. Everything is working great, besides the fact that when batch is executed its pre-pended with a few garbage ascii symbols I cannot figure out where they coming from. Batch script looks simple:

%1 -S .\sqlexpress -i %2

Batch is just executing sqlcmd.exe at a specific location and passes in SQL script to be executed. When I try this manually in command line, it works great, so this is not the generated command itself. Ideas?

This is what build script execution result looks like: ![

   [gallio] D:\Development\project_A\Trunk\build\compile>"D:\Development\project_A\Trunk\build\tools\sqlcmd\SQLCMD.EXE" -S .\sqlexpress -i "C:\Temp\project_A_consolidated_sql_scripts.sql"
   [gallio] '' is not recognized as an internal or external command,
   [gallio] operable program or batch file.
   [gallio] Creating project_A database
   [gallio] Changed database context to 'master'.
   [gallio] Creating project_ADBUser login
   [gallio] Changed database context to 'project_A'.
   [gallio] Creating project_ADBUser user
   [gallio] Creating project_A Schema
   [gallio] Changed database context to 'project_A'.

]Image

Thank you.

+1  A: 

My guess is that you've got a UTF-8 BOM (byte order mark) there. Whether that's in the batch file itself or the command line argument is hard to say though. Where are you getting the data from?

Jon Skeet
The parametrized line (at the top) is in a RunScript.bat file. As for the parameters, they are injected through Process instance I invoke in my C# code, passing them as string parameter. I did have to insert a new line in RunScript.bat so it would work at all, otherwise it was entirely failing. It is working this way, but that error is just so annoying...Thank you for helping.
Sean
Thank you, that was exactly it. I used Notepad++ with HEX editor to remove those three characters and error was gone.
Sean