Launching Process in C# Without Distracting Console Window

Executing an external program via c# without showing the console

Try the following command line switch. It's documented here.

process.StartInfo.Arguments = "-I dummy --dummy-quiet";

How to hide cmd window ,close it and wait for executing automatically

You are looking for this one:

        p1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

Note that MSDN says that

To use ProcessWindowStyle.Hidden, the ProcessStartInfo.UseShellExecute property must be false.

which you do have there, but just in case ...

ProcessStartInfo.CreateNoWindow is something else - this is about whether your process window will host the new process window. The default for this is false, which is what you want, so do not set it to true. I.e. remove

       p1.StartInfo.CreateNoWindow = true;

from your code. You do want the new process to run in its own window, but you want it to be a hidden window. Then you just need to wait for the termination of the new process and it's done.

To wait, you can use WaitForExit. However, I would always recommend you not to wait indefinitely, but always think about a sane limit - could be 30 seconds, 1 minute, 2 minutes ... depends on the task of your child process. And if it takes too long (the child process can be bugged and just hang from unknown reason) then kill it.

Update (using WaitForExit):

The following will wait at most 60 seconds for the child process to finish:

      if (p1.WaitForExit(60 * 1000))
{
// Child process finished, do whatever you want
}
else
{
// Child process failed to finish within 60 seconds, so we kill it.
// It is unlikely that there is a result you are expecting ...
p1.Kill();
}

Suppress command window from started command-line application with .NET

Set the command-line application to a Winforms Application, but don't open a form when it executes, like you usually would.

C# Catching live output from process returns nothing while prosess is running

The solution

After looking into the documentation of C++, I came across the topic of "Flushing output buffers".

The only thing I had to do in the External process was adding the following line of code whenever I wanted the outputted text to be sent away immediately:

cout << "Some string" << someVar;
cout << flush;

how to execute a process while system starting using c# service

You can set the service to Automatic in the Services window and on start execute your code or start a timer to launch shortly after.

Running without launching browser window

Sounds like you are looking for something like phantomjs, or you could try running your tests through a service like BrowserStack. Phantomjs is a headless browser which you can launch from your script, and will provide you with the background browsing you are looking for. BrowserStack is one of a couple services through which you can route your tests; they handle the browser in the background while still offering the capability to view screenshots and run logs. BrowserStack offers a free trial but then is a paid service, so phantomjs might be a better option if it suits your goals.



Related Topics



Leave a reply



Submit