我在E驱动器E:\ 1 \ 2 \ Abc.cmd中有一个文件,并在此文件中写入以下行
@:again
@..\xyz.exe param1 param2
@goto again
xyz.exe路径为E:\ 1 \ xyz.exe
如果我双击abc.cmd然后它工作正常但它在运行表单C#代码时抛出异常。说“..\xyz.exe is not recognized as internal or external commad”
。
我写了以下代码
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = @"E:\1\2\Abc.cmd";
process.StartInfo = startInfo;
process.Start();
答案 0 :(得分:2)
使用此代码
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "E:\\1\\2\\Abc.cmd";
startInfo.WorkingDirectory = "E:\\1\\2\\";
process.StartInfo = startInfo;
process.Start();