Solved

Using a variable in a ProcessStartInfo argument

Posted on 2014-03-30
2
915 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 500 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Service Controller 1 27
C# LINQ ForEach() question 6 54
jquery + C#.net radiobuttonlist 3 30
Powershell script to compare two directory content difference only ? 5 38
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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 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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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