• 2016.1.23 通过cmd在程序中执行sql脚本


    System.Diagnostics.Process pro = new System.Diagnostics.Process();

                pro.StartInfo.FileName = "cmd.exe";

                pro.StartInfo.UseShellExecute = false;

                pro.StartInfo.RedirectStandardInput = true;

                pro.StartInfo.RedirectStandardOutput = true;

                pro.StartInfo.CreateNoWindow = true;

                pro.Start();

     

                //pro.StandardInput.WriteLine("net use \\202.149.225.121\ipc$ "AISchina_Admin" /user:"administrator"");

                //pro.StandardInput.WriteLine("cd D:\程序\");

                //pro.StandardInput.WriteLine("dir *.*");

     

                //重点:下面写入批处理命令时,一定要在末尾换行加上exit,表示退出cmd窗口,

                //同时sql脚本末尾也必须写上exit,表示退出sqlplus,否则程序会一直等待cmd结束,假死。

                string cmd = string.Format(@"sqlplus {0}/ndp@ndp @{1} 

                exit", AisLogical.dbuser, tb_sqlpath.Text);

                pro.StandardInput.WriteLine(cmd);

               

                // 截取输出流

                StreamReader reader = pro.StandardOutput;

                string line = reader.ReadLine();   // 每次读一行

                while (!reader.EndOfStream)  // 不为空则读取

                {

                    if(line!="")

                        tb_output.AppendText(line + Environment.NewLine);  // Environment .NewLine 换行   

                    line = reader.ReadLine().Trim();

                    Application.DoEvents();

                }

                ////

                pro.WaitForExit();

                pro.Close();

  • 相关阅读:
    博客迁移至wordpress--http://i1994898w1.imwork.net/wordpress
    超外差接收机的中频选择
    The Basics of the Doherty Amplifier-Bill Slade [转载]
    闻灾情 忆国殇 山河呜咽 寄哀思
    Simplest Doppler Radar System
    开发人员的奋斗目标
    敏捷开发的推理
    在创业型软件公司的收获
    人才市场的IT职位分析
    MySQL 基础及性能优化工具
  • 原文地址:https://www.cnblogs.com/mol1995/p/5964953.html
Copyright © 2020-2023  润新知