由于存储.exe的路径不同,我无法从C#代码启动.exe。
下面是我如何启动命令行.exe
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = fijiCmdText;
process.StartInfo = startInfo;
process.Start();
_processOn = true;
process.WaitForExit();
ret = 1;
}
catch (Exception ex)
{
ret = 0;
}基本上,fijiCmdText是执行的命令行。
然而,问题是,对于fijiCmdText来说,这样的事情会成功的:
fijiCmdText = "/C D:\\fiji\\ImageJ-win64.exe -macro D:\\fiji\\macros\\FFTBatch.ijm C:\\Users\\myAccount\\Documents\\Untitled005\\ --headless"但是这样的事情是不会成功的:
fijiCmdText = "/C C:\\Users\\myAccount\\Downloads\\fiji (1)\\ImageJ-win64.exe -macro D:\\fiji\\macros\\FFTBatch.ijm C:\\Users\\myAccount\\Documents\\Untitled005\\ --headless".exe的位置似乎很重要。因此,我想知道,除了改变.exe的位置之外,我是否可以在C#代码中处理这个问题,从而使处理不同路径更加灵活和可靠?谢谢。
编辑:都使用命令行运行没有问题。
发布于 2014-02-04 18:17:52
问题是第二条路径包含一个空格,但没有引号分隔它。试试这个:
fijiCmdText = "/C \"C:\\Users\\myAccount\\Downloads\\fiji (1)\\ImageJ-win64.exe\" -macro D:\\fiji\\macros\\FFTBatch.ijm C:\\Users\\myAccount\\Documents\\Untitled005\\ --headless"如果字符串是使用(例如,像下面这样的string.Format )构建的:
fijiCmdText = string.Format("/C {0} -macro {1} {2} --headless",
path1, path2, path3);然后,您应该将其更改为用引号包装所有路径,例如:
fijiCmdText = string.Format("/C \"{0}\" -macro \"{1}\" \"{2}\" --headless",
path1, path2, path3);https://stackoverflow.com/questions/21560181
复制相似问题