Calling unix shell script remotely from C#

前端 未结 3 1459
陌清茗
陌清茗 2021-02-04 19:09

In my current project, i need to call a Unix shell script from the C# application. I also need to get the response back whether the script has been execute successfully or any e

3条回答
  •  一生所求
    2021-02-04 19:39

    A straight forward way of preforming this using System.Diagnostics.Process

    
    // Start the child process.
     Process p = new Process();
     // Redirect the error stream of the child process.
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.RedirectStandardError = true;
     p.StartInfo.FileName = "Write500Lines.exe";
     p.Start();
     // Do not wait for the child process to exit before
     // reading to the end of its redirected error stream.
     // p.WaitForExit();
     // Read the error stream first and then wait.
     string error = p.StandardError.ReadToEnd();
     p.WaitForExit();
    
    

提交回复
热议问题