2

I am using the following code to open the .exe and then I would like to pass another argument to it:

ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = "cmd.exe";
StartInfo.Arguments = @"/k set inetroot=c:\depot&set corextbranch=surfacert_v2_blue_kit&c:\depot\tools\path1st\myenv.cmd";
Process.Start(StartInfo);`

Which opens up the window as below. enter image description here

Now I also need to pass "sd sync dirs" which gives me some result and would like to capture the result to a variable.enter image description here

To accomplish this I need to pass two agruments in the ProcessStartInfo.Arguments. How can I add this second argument in the above code to take care of everything in C# code.

2

2 Answers 2

1

Since its just a string try this:

string[] MyArguments = { "firstarg", "secondarg"};
Process.Start("cmd.exe", String.Join(" ", MyArguments));

Where firstarg and secondarg are your arguments.

EDIT: Oops forgot to tell you ,if your argument contains spaces do this(the example contains 1 argument with spaces-first arg- and 1 without spaces-secondarg):

string[] MyArguments = { "\"first arg\"", "secondarg" };
Sign up to request clarification or add additional context in comments.

2 Comments

Tried but looks like it is not taking the seconde argument. I still see the window as it is shown is the first picture, after running the code.
edited...forgot to tell you sorry,so if your arguments both have spaces do like in first arg example.
0

Here's an example of passing multiple arguments:

http://msdn.microsoft.com/en-us/library/bfbyhds5.aspx

http://msdn.microsoft.com/en-us/library/53ezey2s.aspx

If you're passing strings you need to take account of the possibility of quotes being included in the subject line or body text. I enlisted some help on this issue with a StackOverflow question.

I ended up with something like this:

// DOS command line
C:\>ConsoleApplication1 "Subject Line Text" "Some body text"

// Web form code-behind
// Pass subject and message strings as params to console app    
ProcessStartInfo info = new ProcessStartInfo();

string arguments = String.Format(@"""{0}"" ""{1}""",
     subjectText.Text.Replace(@"""", @""""""),
     messageText.Text.Replace(@"""", @""""""));
     info.FileName = MAILER_FILEPATH;

Process process = Process.Start(info.FileName, arguments);
Process.Start(info);

// Console application
static void Main(string[] args)
{
    if (args.Length >= 2)
    {
        // Do stuff 
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.