C#进程异常

时间:2014-04-27 17:16:15

标签: c#

运行此代码时出现异常

String cmd = "-redir:sim applu.res -max:inst {0} -pred {1} -assoc {2} -lvpt {3} -speedup {4} applu.ss<applu.in";

for (int i = 0; i < parameters.Length; i++) {
    cmd = cmd.Replace ("{" + i + "}", parameters [i]);
}
Console.WriteLine (cmd);

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "./sim-spred";
process.StartInfo.Arguments = cmd;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();    

Console.WriteLine(process.StandardOutput.ReadToEnd());

源位于调试文件夹

1 个答案:

答案 0 :(得分:1)

由于您没有告诉我们异常的位置,我不知道这是否与您的问题有关。但是,

这就是String.Format存在的原因!

String cmd = "-redir:sim applu.res -max:inst {0} -pred {1} -assoc {2} -lvpt {3} -speedup {4} applu.ss<applu.in";

for (int i = 0; i < parameters.Length; i++) {
    cmd = cmd.Replace ("{" + i + "}", parameters [i]);
}

请改为尝试:

var cmd = String.Format("-redir:sim applu.res -max:inst {0} -pred {1} -assoc {2} -lvpt {3} -speedup {4} applu.ss<applu.in",
    max_inst, pred, assoc, lvpt, speedup);