I threw this together, and maybe someone will find it useful.
I needed to be able to interact with cmd.exe a bit more than the native system exec.vi primitive offers. I used .NET to get the job done. Some notable capabilities:
- User can see standard output and standard error in real-time
- User can write a command to standard input
- User can query if the process has completed
- User can abort the process by sending a ctrl-C command
Aborting the process was the trickiest part. I found a solution at the following article:
http://stanislavs.org/stopping-command-line-applications-programatically-with-ctrl-c-events-from-net/#comment-2880
The ping demo illustrates this capability. In order to abort ping.exe from the command-line, the user needs to send a ctrl-c command. We achieve this by invoking KERNEL32 to attach a console to the process ID and then sending a ctrl-C command to the process. This is a clean solution that safely aborts ping.exe. The best part about this solution is that it doesn't require for any console prompts to be visible. An alternate solution was to start the cmd.exe process with a visible window, and then to issue a MainWindowClose command, but this required for a window to be visible.
I put this code together to allow for me to better interact with HandbrakeCLI and FFMPEG. Enjoi
NET_Proc.zip