F. Linnenberg
F. Linnenberg

Reputation: 42

C# start program with arguments containing strings

I want to start a program using this code:

private void PBox_Banner_Click(object sender, EventArgs e)
{
    string JavaPath = @"C:\Program Files\Java\jre8\bin\javaw.exe";
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = JavaPath;
    startInfo.Arguments = @"-Xmx1024-jar "D:\Log4-cg.jar"";
    Process.Start(startInfo);
}

The problem is that I have to use a string within the argument string.

I am using Microsoft Visual Studio Express 2012 for Windows Desktop.

Upvotes: 1

Views: 110

Answers (2)

SingleStepper
SingleStepper

Reputation: 348

If David's solution doesn't work, the old-school fallback should:

startInfo.Arguments = "-Xmx1024-jar \"D:\\Log4-cg.jar\"";

Upvotes: 0

David Crowell
David Crowell

Reputation: 3813

Doubling up on the quotes should fix it.

startInfo.Arguments = @"-Xmx1024-jar ""D:\Log4-cg.jar""";

Upvotes: 2

Related Questions