I'm trying to run a python script from a C# console app, the script is a simple CLI application. The problem is that when I run the console application, the output terminal does not show me any result returned from python script.
Python Script:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('FirstName')
parser.add_argument('LastName')
args = parser.parse_args()
first_name = args.FirstName
last_name = args.LastName
print(f"{first_name} {last_name}")
C# Code
namespace CS_PythonTest
{
internal class Program
{
static void Main(string[] args)
{
var psi = new ProcessStartInfo();
psi.FileName = @"\python.exe";
var script = "\pythonScript.py";
psi.Arguments = $"{script}";
psi.UseShellExecute = false;
psi.CreateNoWindow= true;
psi.RedirectStandardOutput= true;
psi.RedirectStandardError= true;
var errors = "";
var results = "";
using (var process = Process.Start(psi)) {
errors = process.StandardError.ReadToEnd();
results= process.StandardOutput.ReadToEnd();
}
Console.WriteLine(results);
}
}
}