Using a variable in a ProcessStartInfo argument
Posted on 2014-03-30
I have two variables that get the path of the console application
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
var directory = System.Io.Path.GetDirectoryName(path);
I now have the path that I want in the directory variable. for example "c:\somedirectory"
I am using ProcessStartInfo to run a sqlcmd query and I want to pass the value of directory to the -o (output file) switch. I don't want to hardcode this as this app is going to run on multiple boxes.
ProcessStartInfo ProcessProperties = new ProcessStartInfo("sqlcmd.exe");
ProcessProperties.Arguments = @"-S localhost -d master -o ??????????\output.txt -Q ""SET NOCOUNT ON;DROP database test;Declare @varoutput varchar(30);SELECT @varoutput = [name] FROM sys.databases where [name] = 'test';SELECT Case when @varoutput is Null then '0' else @varoutput end;""";
Any help is appreciated.