locked
Convert .bat file to C# RRS feed

  • Question

  • How can I read a .bat file in c# language? How to translate the Batch commands into C#?  
    Wednesday, September 14, 2016 12:24 PM

Answers

  • I suppose something like:

    1) Read the batch line by line with System.IO.StreamReader.
    2) Use System.Diagnostics.Process.Start() with .UseShellExecute set to true to run the lines.

    P.S.: If your batch file use environment variables or batch conditions to set some logic, you're recommanded to use "cmd /k" to run the lines though. Beware that in batch file you use %% for naming those temporary variables but in command line you only use %.

    Also, maybe you should handle the goto cases to jump lines yourself.

    Thursday, September 15, 2016 2:07 AM
    Answerer