Reputation: 805
I'm trying to run a code on command prompt using this code:
ProcessStartInfo startInfo = new ProcessStartInfo("Cmd");
startInfo.Arguments = "/c tracert 8.8.8.8";
Process.Start(startInfo);
But it closes after running code but I want cmd stay open. What should I do?
Upvotes: 0
Views: 2184
Reputation: 18299
Add a pause
command
ProcessStartInfo startInfo = new ProcessStartInfo("Cmd");
startInfo.Arguments = "/c tracert 8.8.8.8 & pause";
Process.Start(startInfo);
Upvotes: 1
Reputation: 2008
The /c
argoument is telling CMD to close after the instructions are done.
Instead, if you want to keep the window open and return to the terminal, you should use the /k
switch:
ProcessStartInfo startInfo = new ProcessStartInfo("Cmd");
startInfo.Arguments = "/k tracert 8.8.8.8";
Process.Start(startInfo);
Upvotes: 6