CosminPetrescu
CosminPetrescu

Reputation: 43

Cmd process not accepting command?

I am trying to read the output of the command with the following argument.

ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.Arguments = "nvidia-smi --query-gpu=utilization.memory --format=csv";
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;
Debug.Write("Test1 \n"); // it prints
Process process = Process.Start(processStartInfo);
using (StreamReader streamReader = process.StandardOutput)
{
    Debug.Write("Test2 \n"); // it prints
    output = streamReader.ReadToEnd();
    Debug.Write("Test3 \n"); // it doesn t print
}

String[] substrings = output.Split(delimiter2);

I should mention that the command is valid if i run it manually.

Upvotes: 1

Views: 194

Answers (1)

Prateek Shrivastava
Prateek Shrivastava

Reputation: 1937

Here is what you need:

ProcessStartInfo processStartInfo = new ProcessStartInfo("nvidia-smi");
processStartInfo.Arguments = "--query-gpu=utilization.memory --format=csv";
processStartInfo.UseShellExecute = false;

Firstly - cmd.exe is not the binary you want to launch, because it doesnt have nvidia command line arguments. You actually want to launch - nvidia-smi.

You may face exceptions like File Not Found if nvidia-smi is not in your PATH variable. I nthat case you will have to use FULL PATH to the binary.

Updated: 25/02/2020

The following works for me: enter image description here

Also note that my compilation targets 64 bit: enter image description here

Upvotes: 1

Related Questions