I want to execute a TEST.exe in a C program. While I use
system( \"TEST.exe output-file\" );
I can get what I expected.<
system
actually spawns a cmd
instance in which your command is run:
The system function passes command to the command interpreter, which executes the string as an operating-system command. system refers to the COMSPEC and PATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows NT). If command is NULL, the function simply checks to see whether the command interpreter exists.
—Documentation of system
This is why redirection operators such as <
and >
work. This is not the case for CreateProcess
which really just spawns a process instead of a shell that executes another process. Since the redirection operators are a feature of the shell and not the OS you'd have to do input and output to the process manually.