Solved

Using a variable in a ProcessStartInfo argument

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data is not showing from images 15 38
VB.Net How to Exit Sub - Exit Form??? 5 51
Turn on intranet settings 1 41
Video Player 2017 5 14
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

896 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

11 Experts available now in Live!

Get 1:1 Help Now