Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using a variable in a ProcessStartInfo argument

Posted on 2014-03-30
2
Medium Priority
?
1,065 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 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39964955
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
ID: 39965009
Thank you.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

916 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