0

I want to execute a string in c# as a .cmd. Is this possible without first saving it as a file on disk and then use Process.Start to execute the file? If so, please come with an example of how to do that in C#.

Abris
  • 1,451
  • 3
  • 18
  • 38

1 Answers1

3

I believe this can be done by simply using cmd.exe as your child process, redirecting StandardInput and simply feeding your string into this redirected StandardInput to make cmd.exe interpret it as batch and run it. The command echo dir | cmd.exe works and so I'd expect Process.Start to work as well.

LB2
  • 4,802
  • 19
  • 35