Welcome to OStack Knowledge Sharing 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...