run external exe file from dotnet core console application

2.1k Views Asked by At

I came across this question after several searches online. But none of them seemed to answer perfectly. If there is any good reference that someone can lead me to that is also very good. Thanks in advance.

I have two console applications running in dotnet core 2.2. The console applications are basically chatting clients, using NATS Server. One being the publisher and the other consumer, I am using both projects as startup projects in the solution. Both of the projects are connecting to NATS server initially, so the NATS server needs to be executed prior to my publisher or consumer. The command to run the NATS server is nats-server --user DemoUser

The NATS server is an executable file, I want to my consumer/publisher to execute the command somehow to run the nats-server.

1

There are 1 best solutions below

0
Mortaza Ghahremani On

You can run command in another process like below :

var command = "nats-server --user DemoUser";
var proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = "nats-server.exe",/// @"C:\Windows\System32\cmd.exe",
                        Arguments = command,
                        RedirectStandardInput = false,
                        RedirectStandardError = false,
                        UseShellExecute = false,
                        RedirectStandardOutput = true,
                        CreateNoWindow = false
                    }
                };
                proc.Start();