Execute multiple command lines with the same process using C#
Posted
by rima
on Stack Overflow
See other posts from Stack Overflow
or by rima
Published on 2010-05-17T17:48:08Z
Indexed on
2010/05/17
18:10 UTC
Read the original article
Hit count: 391
Hi according to my last question here I try to write a sql Editor or some thing like this,in this way I try to connect to CMD from C# and execute my command. now my problem is for example I connect to SQLPLUS after that I cant get SQLPLUS command,and the other resource I review don't satisfy me.Please help me how after I connected to Sqlplus ,I can a live my process to run my sql command? right now I use this code:
//Create process
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
//strCommand is path and file name of command to run
pProcess.StartInfo.FileName = strCommand;
//strCommandParameters are parameters to pass to program
pProcess.StartInfo.Arguments = strCommandParameters;
pProcess.StartInfo.UseShellExecute = false;
//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = true;
//Optional
pProcess.StartInfo.WorkingDirectory = strWorkingDirectory;
//Start the process
pProcess.Start();
//Get program output
string strOutput = pProcess.StandardOutput.ReadToEnd();
//Wait for process to finish
pProcess.WaitForExit();
but i customize it.I separate the initialize, i mean i just create process object one time,but I still have problem. to run the second command I use these codes for second time calling:
pProcess.StartInfo.FileName = strCommand;
//strCommandParameters are parameters to pass to program
pProcess.StartInfo.Arguments = strCommandParameters;
//Start the process
pProcess.Start();
//Get program output
string strOutput = pProcess.StandardOutput.ReadToEnd();
//Wait for process to finish
pProcess.WaitForExit();
Thanks in advance
© Stack Overflow or respective owner