Reputation: 43
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
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
Also note that my compilation targets 64 bit:
Upvotes: 1