I did it with cmd.exe/sh. My procedure creates .bat/.sh file with four lines -
1) echo Start
2) cmd.exe /c command_string (or sh -c command_string)
3) echo End
4) read line
and executes it. The structure of the call is always the same:
- the executable is cmd.exe/sh;
- 1st parameter is /c or -c;
- next parameters are in command_string.
It works.
And it makes another problem. Command_strings are configurable by the user. They may contain spaces, quote characters etc. Here their parsing is up to the command-line interpreter. But I also need the ability to execute the same command_strings without delays and console windows, directly, without .bat/.sh files. I need uniform parsing. For direct execution, I use Process.Executable with Process.Parameters and CommandToList to parse command_string. But CommandToList has its own parsing rules, and I cannot rewrite it for identical results with command-line interpreters. Should I use Process.CommandLine instead? (it's deprecated).