0

I'm trying to write a front end application that makes use of existing tools (that are run from batch files) to create bootable media for a Ryzen Hackintosh. I don't want to modify the existing tools as I would have to manually update the front end every time the existing tools get updated. I can run the batch files on their own with "Process.Start(file);" but the batch files require inputs, and I'd like to input to them programmatically, rather than give the user instructions on what to do when the cmd window pops up.

I've tried this style of running the file with cmd as a new process and redirecting input + output ( Executing Batch File in C# ), but this doesn't seem to launch cmd at all, and hard-locks the program with no error messages.

I have also tried using AllocConsole/FreeConsole too.

static void ExecuteCommand(string command, string input)
        {
            Console.WriteLine("Test if this thing works");

            Process pro = new Process();
            pro.StartInfo.FileName = command;
            pro.StartInfo.UseShellExecute = false;
            pro.StartInfo.RedirectStandardInput = true;
            pro.StartInfo.RedirectStandardOutput = true;
            pro.Start();
            string result = pro.StandardOutput.ReadToEnd();
            Console.WriteLine(result);
        }

I expect the batch file to run, then print the contents of the output to the console, but instead no window appears, the batch file doesn't appear to run and the program freezes with no error messages. I have also used try/catch to see and errors but none appeared.

Andymanic
  • 11
  • 2
  • `StartInfo.FileName` should be `cmd.exe` (started with `/k` or `start /WAIT`), its `Arguments` the batch file (+ switches, if any). If you need to pass commands, also redirect StandardInput. See this example: [How do I get output from a command to appear in a control on a Form in real-time?](https://stackoverflow.com/a/51682585/7444103) – Jimi Jun 23 '19 at 10:52
  • Jimi - the linked article is exactly what I was after, I'll modify it to work with what I need. Thank you very much. – Andymanic Jun 23 '19 at 13:39

0 Answers0