0

before i start... I realize that there were some issues like this one. But still,I can't find an answer that satisfies me. Down below, I placed my code:

private void run_cmd(string cmd, string args)
        {
            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = "cmd.exe";
            start.Arguments = $"C:/Users/Ola/AppData/Local/Programs/Python/Python38/python.exe 
{cmd} {args}"; // where these args come with parameters
            start.UseShellExecute = false;
            start.RedirectStandardOutput = true;
            start.WindowStyle = ProcessWindowStyle.Hidden;
            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string result = reader.ReadToEnd();
                    Console.Write(result);
                }
            }
}

Can anyone tell me this class does not work properly? The output is just blank cmd window.

Alex C
  • 13
  • 1
  • https://stackoverflow.com/questions/11779143/how-do-i-run-a-python-script-from-c – Roman Ryzhiy Aug 31 '20 at 13:26
  • 1
    There is a common mishap here: Instead of starting the exe you actually want to start, you start a CMD that is supposed to start the desired exe. So, while the actual question has already been answered on SO, you may want to dig into this problem, too, so you don't repeat it. – Fildor Aug 31 '20 at 13:28
  • Thank you, now I see my mistake! Code bless you! – Alex C Sep 01 '20 at 10:25

0 Answers0