zoukankan      html  css  js  c++  java
  • C# 中启动进程的三种方法

    1.启动子进程,不等待子进程结束
    private void simpleRun_Click(object sender, System.EventArgs e)
    { System.Diagnostics.Process.Start(@"C:\listfiles.bat");
    }
    2.启动子进程,等待子进程结束,并获得输出
     1private void runSyncAndGetResults_Click(object sender, System.EventArgs e)
     2{
     3    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat"); 
     4    psi.RedirectStandardOutput = true; 
     5    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
     6    psi.UseShellExecute = false; 
     7    System.Diagnostics.Process listFiles; 
     8    listFiles = System.Diagnostics.Process.Start(psi); 
     9    System.IO.StreamReader myOutput = listFiles.StandardOutput; 
    10    listFiles.WaitForExit(2000);
    11    
    12    if (listFiles.HasExited)  
    13    {  
    14        string output = myOutput.ReadToEnd();  
    15        this.processResults.Text = output; 
    16    }
    17}
    183.使用默认的浏览器打开URL
    1private void launchURL_Click(object sender, System.EventArgs e)
    2{ 
    3    string targetURL = @http://www.duncanmackenzie.net/
    4    System.Diagnostics.Process.Start(targetURL);
    5}
  • 相关阅读:
    抽象工厂模式
    python 工厂方法
    采用__call__ 实现装饰器模式
    策略模式
    采集15个代理IP网站,打造免费代理IP池
    grid网格布局——色子布局
    观察者模式
    搭建免费代理池---采集代理(1)
    python 爬虫 user-agent 生成
    多进程 + 多线程抓取博客园信息
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/1370565.html
Copyright © 2011-2022 走看看