running dos command line from C#?

你。 提交于 2019-11-29 03:54:12
Nick X Tsui

The problem was solved as in the direction Chris Haas pointed out. It does not mean other answers don't work, it just means the problem can be solved at least in one way.

Here it is, simply adding "/C " in the code, and it should work:

Original that did not work:

string fijiCmdText = "D:\\fiji\\fiji.exe -macro D:\\fiji\\macros\\FFTBatch.ijm --headless";
System.Diagnostics.Process.Start("cmd.exe", fijiCmdText)

;

Current code that works:

string fijiCmdText = "/C D:\\fiji\\fiji.exe -macro D:\\fiji\\macros\\FFTBatch.ijm --headless";
System.Diagnostics.Process.Start("cmd.exe", fijiCmdText);

Here is the reference mentioned by Chris Haas. See EDIT3

You don't have to run cmd.exe, just create ProcessStartInfo object and pass the command with its parameters to it. Like this:

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("your command", "parameters");

Here is an example that shows you how to do it:

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("tree.com", "/f /a");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = info;
p.Start();
p.WaitForExit();

So in your case, this is your command: "D:\\fiji\\fiji.exe" and this is your command parameters or arguments: @"-macro D:\\fiji\\macros\\FFTBatch.ijm --headless"

Try This:

ProcessStartInfo info = new ProcessStartInfo(@"D:\fiji\fiji.exe",@"-macro D:\fiji\macros\FFTBatch.ijm --headless");
Process process = new Process();
process.StartInfo = info;
process.Start();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!