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
1.0k views
in Technique[技术] by (71.8m points)

.net - Any way to keep an external command window open during a Process.Start(..)?

i've got the following code which runs a bat file. the bat file then runs some .exe .. which does some stuff. The stuff takes aroun 5-10 seconds.

ProcessStartInfo start = new ProcessStartInfo
{
    Arguments = """ + newTargetFile + """ +
                " " +
                """ + originalFile.FullName + """,
    FileName = filename,
    WindowStyle = ProcessWindowStyle.Normal,
    CreateNoWindow = false,
    UseShellExecute = false
};

// Run the external process & wait for it to finish
using (Process proc = Process.Start(start))
{
    proc.WaitForExit();
}

What i'm trying to do is leave the command window open, even after the process terminates. Is there any way to do this?

Otherwise, can i get all the output of that window going to my debugger instead, so i don't need to worry about this window remaining?

cheers.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

If you run the cmd interpreter with a /k argument and pass in the batch file name as the next argument, you should get what you're after. The /k argument tells Windows to leave the cmd interpreter open when it's done with whatever you tell it to do as the next argument.

You could certainly also use the RedirectStandardOutput property, but I think that would be more complicated in the end.


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

...