Executing batch with parameters using Process
I am trying开发者_如何学C 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.
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?
精彩评论