0

I have a ruby script which I am trying to execute using Process from my program. After certain event, I want to stop its execution. I tried sending the ctrl + c using the solution provided in the quetsion How do I send ctrl+c to a process in c#? however its not working for me. Can anyone provide better solution? Below is the code:

string command = @"/c ruby C:\MyRubyProgram GetThis GetThat";

        ProcessStartInfo start_info = new ProcessStartInfo("cmd", command);
        start_info.UseShellExecute = false;
        start_info.RedirectStandardOutput = true;
        start_info.RedirectStandardInput=true;

        Process process = new Process();
        process.StartInfo = start_info;

        process.Start();
        process.WaitForExit();

        process.StandardInput.WriteLine("\x3");
        process.StandardInput.Close();
        Console.Write(process.StandardOutput.ReadToEnd());

Community
  • 1
  • 1
Tejas
  • 391
  • 2
  • 7
  • 19

2 Answers2

0

Why not process.Kill() ? It should help..

kmatyaszek
  • 19,016
  • 9
  • 60
  • 65
Eugene Petrov
  • 651
  • 1
  • 5
  • 14
0

you can use this code to kill the process. When it is finished.

process.WaitForExit();
Musakkhir Sayyed
  • 7,012
  • 13
  • 42
  • 65