954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

call cmd processes and keeping them cmd window

I've been able to call a cmd process to run a batch file. It runs but I have no idea what it does bec' the window opens and closes too fast. I've used .WaitForExit(), but it doesn't help. I've been looking for more help and can find anything specific. I can't tell if my batch file runs or not and where the output redirects too. Any help would be greatly appreciated. Thanks.

Gabe

GRaymer
Newbie Poster
13 posts since Sep 2007
Reputation Points: 10
Solved Threads: 1
 

You remind me with graduation project days :)

public void GenerateKeyFile(string command)
        {
            ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
            PSI.RedirectStandardInput = true;
            PSI.RedirectStandardOutput = true;
            PSI.RedirectStandardError = true;
            PSI.UseShellExecute = false;
            Process p = Process.Start(PSI);
            System.IO.StreamWriter SW = p.StandardInput;
            System.IO.StreamReader SR = p.StandardOutput;
            SW.WriteLine(command);
            SW.Close();
        }
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

ok, quick and dirty, to be removed before building release - used to help me in my student years. Last line of code is :
Console.ReadLine();

that will wait until you kill the console.

tostrinj
Newbie Poster
21 posts since Jul 2007
Reputation Points: 12
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You