Process.start: how to get the output?

后端 未结 9 1536
無奈伤痛
無奈伤痛 2020-11-21 23:56

I would like to run an external command line program from my Mono/.NET app. For example, I would like to run mencoder. Is it possible:

  1. To get
9条回答
  •  孤城傲影
    2020-11-22 00:37

    How to launch a process (such as a bat file, perl script, console program) and have its standard output displayed on a windows form:

    processCaller = new ProcessCaller(this);
    //processCaller.FileName = @"..\..\hello.bat";
    processCaller.FileName = @"commandline.exe";
    processCaller.Arguments = "";
    processCaller.StdErrReceived += new DataReceivedHandler(writeStreamInfo);
    processCaller.StdOutReceived += new DataReceivedHandler(writeStreamInfo);
    processCaller.Completed += new EventHandler(processCompletedOrCanceled);
    processCaller.Cancelled += new EventHandler(processCompletedOrCanceled);
    // processCaller.Failed += no event handler for this one, yet.
    
    this.richTextBox1.Text = "Started function.  Please stand by.." + Environment.NewLine;
    
    // the following function starts a process and returns immediately,
    // thus allowing the form to stay responsive.
    processCaller.Start();    
    

    You can find ProcessCaller on this link: Launching a process and displaying its standard output

提交回复
热议问题