c#调用外部程序

 private System.Timers.Timer m_timer;
   
    void Application_Start(object sender, EventArgs e)
    {
        m_timer = new System.Timers.Timer(1000);
        m_timer.Enabled = true;
        m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed);  //事件代理
        //开启时钟。
        m_timer.Start();

    }       

//定时执行 事件

 private void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs args)
    {

string mypath = "cd " + HttpRuntime.AppDomainAppPath;
        Process p = new Process();
        p.StartInfo.FileName = "cmd.exe";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardInput = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.CreateNoWindow = true;
        p.Start();
       // p.StandardInput.WriteLine("c:");
        p.StandardInput.WriteLine(mypath);
        p.StandardInput.WriteLine("s.pl");
        p.StandardInput.WriteLine("md ok8");
        p.StandardInput.WriteLine("exit");
        string myreult = p.StandardOutput.ReadToEnd();
        p.Close();
        File.WriteAllText(@"C:\re.txt", myreult);

}

原文地址:https://www.cnblogs.com/a311300/p/1806420.html