Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
666 views
in Technique[技术] by (71.8m points)

running dos command line from C#?

I am trying to run this command from command-line prompt:

"D:\fiji\fiji.exe -macro D:\fiji\macros\FFTBatch.ijm --headless"

It works perfect when I type it in a command-line console.

However, when I was trying to make it work from C# application, it failed. I tried following, but seems the command above did not get executed somehow:

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

Anyone has any idea how to change it to work? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...