Solved

Using a variable in a ProcessStartInfo argument

Posted on 2014-03-30
2
862 Views
Last Modified: 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.
0
Comment
Question by:sherbug1015
2 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
You can use string.Format for this:

ProcessProperties.Arguments = string.Format(@"-S localhost -d master -o ""{0}"" \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;""", path);

Open in new window

0
 

Author Closing Comment

by:sherbug1015
Comment Utility
Thank you.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now