日期:2014-05-17  浏览次数:20722 次

【请教】C#调用oracle中的exp.exe无法显示DOS下的屏幕输出
private void button12_Click(object sender, EventArgs e)
        {
            #region oracle数据库备份
            System.Diagnostics.Process pro = new System.Diagnostics.Process();
            pro.StartInfo.FileName = "cmd.exe ";
            pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
            pro.StartInfo.CreateNoWindow = true;
            pro.StartInfo.UseShellExecute = false;
            pro.StartInfo.RedirectStandardInput = true;
            pro.StartInfo.RedirectStandardOutput = true;
            pro.Start();
            //pro.StandardInput.WriteLine("exp  lc1002/cccccc@orcl file=lc100220101113.dmp owner=lc1002");
            pro.StandardInput.WriteLine("exp " + textBox2.Text + "/" + textBox3.Text + "@" + textBox1.Text + " file=" + textBox4.Text + textBox2.Text + ".dmp" + " owner=" + textBox2.Text);
           
            pro.StandardInput.WriteLine("exit");
            
            string outPut = pro.StandardOutput.ReadToEnd();
            this.textBox4.Text = outPut;

            MessageBox.Show("ORACLE数据库备份完成!", "提示");

            #endregion
        }

运行后可以成功备份数据,但是textBox4只显示运行cmd.exe和exit了。

没有显示平时在DOS下执行exp.exe时在屏幕上输出的详细内容,像导出的表名,导出了多少行等等。

请各位老师帮忙看看,谢谢!

------解决方案--------------------
两个方法:

简单的:exp命令最后加上重定向,类似"exp xxxxx > output.txt",这样会把中断下显示的内容转存到output.txt里,然后再读取这个文件就可以了。

复杂的:Google一下winform如何显示终端内容