The problem is this, I call the script (__FileName) from my application, here’s the code:

private void runToolStripMenuItem_Click(object sender, EventArgs e) { var psi = new ProcessStartInfo { FileName = "ruby.exe", Arguments = __FileName, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }; var p = Process.Start(psi); textBox2.Text = p.StandardOutput.ReadToEnd() + p.StandardError.ReadToEnd(); } 

the script window appears and disappears immediately, even if you write "gets" in the script. What to do? Thank you in advance.

  • I wrote to you in the previous answer that you need to add p.WaitForExit() ; - andreycha
  • Yes, thanks, but still, unfortunately, does not help. - Eugene
  • Open the console and try to run this application with the same parameters. Anything out? - andreycha
  • The application works correctly if you launch it through the console or even by double-clicking it with the left mouse button. - Eugene
  • And try to run as administrator: psi.Verb = "runas"; - Andreycha

1 answer 1

The problem is that you start the console application and upon closing it automatically closes the console.

That is, I see 2 options:

  1. And if you open the console and you already run the script in it, the window will not close. Because at the end of the program, it will simply return to the open console, and not close the window

  2. In the script itself, write down the ReadKey at the end of the script itself. The result will be approximately the same.