zoukankan      html  css  js  c++  java
  • 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();

  • 相关阅读:
    vijos1198:最佳课题选择
    vijos1071:新年趣事之打牌
    vijos1153:猫狗大战
    bzoj3594: [Scoi2014]方伯伯的玉米田
    bzoj2753: [SCOI2012]滑雪与时间胶囊
    bzoj1923: [Sdoi2010]外星千足虫
    bzoj2783: [JLOI2012]树
    bzoj4590: [Shoi2015]自动刷题机
    bzoj4580: [Usaco2016 Open]248
    bzoj4579: [Usaco2016 Open]Closing the Farm
  • 原文地址:https://www.cnblogs.com/mol1995/p/5964953.html
Copyright © 2011-2022 走看看