Search code examples
c#selenium-rc

When using Process.Start(), how can I keep the cmd prompt open for the duration of the program?


Right now I'm trying to use C# to open wither a .java server, or a .bat file that launched the same server. I am able to launch it fine, however if quickly closes since the single command I wanted to perform executed. The problem is I need to keep the cmd window open in order to keep the server up.

I have a few different version of how I want to start the process, this being the shortest one to post:

Process seleniumServer;
ProcessStartInfo seleniumServerProcessStartInfo = new ProcessStartInfo("java", @"C:\Users\full\path\to\file\selenium-server.jar");
Process.Start(seleniumServerProcessStartInfo);

How can I make sure the cmd window that popups which launches the selenium-server.jar file keeps open until the program closes?


Solution

  • Launch it with "-jar foo.jar" as args, like:

    ProcessStartInfo seleniumServerProcessStartInfo = new ProcessStartInfo("java", @"-jar C:\Users\full\path\to\file\selenium-server.jar");
    

    The window is probably disappearing because the jar never gets launched.