-3

I have a command line which run a c# executale. while it's running, I'd like the c# executable to input on the command line some command. I want this because I want to know in the command line which commands were called and the results.

I also need to fetch the results.

The commands the c# executable generate may be things from cd .. to execute another executable through mono fetch.exe

without a process How To: Execute command line in C#, get STD OUT results

something like

Console.WriteLine but which would execute the line in the same time since the exe is executed throught the window

Community
  • 1
  • 1
Nissa Armelon
  • 101
  • 2
  • 11

1 Answers1

1

Shell commands cannot be executed within the same process. If you really want to execute direct, arbitrary shell commands, you can just run cmd /c <command> with Process.Start for any command. Note that &&, ||, & can be used to make a more interesting single command. (If you want to stream multiple commands to the same process, you can even send shell commands via stdout but this is more effort to set up).

However you shouldn't need to run shell commands because the equivalent functionality exists in C# and is more efficient than shell commands because shell commands are interpreted (whereas C# is compiled). For example, you can use startInfo.WorkingDirectory (from process.StartInfo) to emulate the effect of "cd .."

VoidStar
  • 5,241
  • 1
  • 31
  • 45