Hi all
refer to these post : here1 and here2 at last I solve my problem by build a asynchronous solution,and it work well!!! but there is a problem that i face with it,now my code is like this:
class MyProcessStarter
{
private Process process;
private StreamWriter myStreamWriter;
private static StringBuilder shellOutput = null;
public String GetShellOutput { get { return shellOutput.ToString(); }}
public MyProcessStarter(){
shellOutput = new StringBuilder("");
process = new Process();
process.StartInfo.FileName = "sqlplus";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.OutputDataReceived += new DataReceivedEventHandler(ShellOutputHandler);
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
//process.StartInfo.RedirectStandardError = true;
process.Start();
myStreamWriter = process.StandardInput;
process.BeginOutputReadLine();
}
private static void ShellOutputHandler(object sendingProcess,DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
shellOutput.Append(Environment.NewLine + outLine.Data);
}
public void closeConnection()
{
myStreamWriter.Close();
process.WaitForExit();
process.Close();
}
public void RunCommand(string arguments)
{
myStreamWriter.WriteLine(arguments);
myStreamWriter.Flush();
process.WaitForExit(100);
Console.WriteLine(shellOutput);
Console.WriteLine("============="+Environment.NewLine);
process.WaitForExit(2000);
Console.WriteLine(shellOutput);
}
}
and my input is like this:
myProcesStarter.RunCommand("myusername/mypassword");
Console.writeline(myProcesStarter.GetShellOutput);
but take a look at my out put:
SQL*Plus: Release 11.1.0.6.0 - Production on Thu May 20 11:57:38 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
=============
SQL*Plus: Release 11.1.0.6.0 - Production on Thu May 20 11:57:38 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Enter user-name:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
as u see the output for run a function is not same in different time!So now would you do me a faver and help me that how I can wait until all the output done in other mean how I can customize my process to wait until output finishing ?? because I want to write a sqlcompiler so I need the exact output of shell.
plz help me soon.thanxxxxxxxxxxxx :X