Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#使用包含字符串的参数启动程序_C# - Fatal编程技术网

C#使用包含字符串的参数启动程序

C#使用包含字符串的参数启动程序,c#,C#,我想用以下代码启动一个程序: 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.A

我想用以下代码启动一个程序:

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);
}
问题是我必须在参数字符串中使用字符串


我正在使用Microsoft Visual Studio Express 2012 for Windows Desktop。

将引号加倍应该可以解决此问题

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

如果David的解决方案不起作用,老派的退路应该:

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

是否将“D:\Log4 cg.jar”放在“s”中而不是“s help”@farhad alinoo不,因为Java会崩溃。您应该替换字符
“-Xmx1024 jar\”D:\\Log4 cg.jar\”";谢谢你,这很有效,但我必须等8分钟才能接受你的回答。斯卡吉特:你可以按照这里的建议去做,也可以像@FarhadAliNoo对你的问题的评论中提到的那样简单地使用撇号。