C# 如何在异步过程中从shell中完全检索结果?

C# 如何在异步过程中从shell中完全检索结果?,c#,plsql,io,asynchronous,C#,Plsql,Io,Asynchronous,参考这些帖子:最后,我通过构建一个异步解决方案来解决我的问题,它工作得很好!!!但我面临一个问题,现在我的代码是这样的: class MyProcessStarter { private Process process; private StreamWriter myStreamWriter; private static StringBuilder shellOutput = null; public String Get

参考这些帖子:最后,我通过构建一个异步解决方案来解决我的问题,它工作得很好!!!但我面临一个问题,现在我的代码是这样的:

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);            
        }
    } 
 myProcesStarter.RunCommand("myusername/mypassword");
 Console.writeline(myProcesStarter.GetShellOutput);
我的输入是这样的:

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);            
        }
    } 
 myProcesStarter.RunCommand("myusername/mypassword");
 Console.writeline(myProcesStarter.GetShellOutput);
但看看我的输出:

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
正如你所看到的,运行函数的输出在不同的时间是不一样的!那么现在你能帮我一个忙吗?我怎样才能等到所有的输出都完成了,换句话说,我怎样才能定制我的流程,直到输出完成??因为我想写一个sqlcompiler,所以我需要shell的精确输出


请尽快帮助我。在SQL*Plus上,您应该使用
-S
参数。根据帮助,这个参数

设置静默模式,以抑制 显示SQL*Plus横幅, 提示和命令的回显

理想情况下,这将使输出一致