I’m trying to verify current python version. Since I’ll check a lot of requirements for my app, it should be done via CMD using C# Process.Start()
Real CMD output (without a code, just using cmd.exe
from Windows.
input:
python.exe --version
output:
Python 3.12.4
C# version code:
var startInfo = new ProcessStartInfo();
startInfo.FileName = @"python.exe";
startInfo.Arguments = @"--version";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
startInfo.LoadUserProfile = true;
using var process = Process.Start(startInfo);
using var outputReader = process.StandardOutput;
string output = outputReader.ReadToEnd();
using var errorReader = process.StandardError;
string error = errorReader.ReadToEnd();
Output, output
variable is empty, error
variable content:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Is it possible to get the same behavior in C# like just manually calling CMD?