Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.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#启动.exe时,路径可能很重要?_C#_Command Line_Path - Fatal编程技术网

从C#启动.exe时,路径可能很重要?

从C#启动.exe时,路径可能很重要?,c#,command-line,path,C#,Command Line,Path,由于存储.exe的路径不同,从C#代码启动.exe时遇到问题 下面是我如何启动命令行.exe的 try { System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle

由于存储.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#代码中处理这个问题,从而使处理不同路径更灵活、更可靠?谢谢

编辑:
两者都可以使用命令行运行。

问题在于第二条路径包含空格,但没有引号分隔。试试这个:

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);

问题是第二条路径包含一个空格,但没有引号来分隔它。试试这个:

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);

问题是第二条路径包含一个空格,但没有引号来分隔它。试试这个:

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);

问题是第二条路径包含一个空格,但没有引号来分隔它。试试这个:

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);

当然.EXE的位置很重要。除此之外,如何确保正在执行所需的文件?当然.EXE的位置很重要。除此之外,如何确保正在执行所需的文件?当然.EXE的位置很重要。除此之外,如何确保正在执行所需的文件?当然.EXE的位置很重要。否则,您将如何确保正在执行预期的文件?