"Virtual" Command Prompt
-
Hi All, I am trying to add a cmd functionality into my app, however it's not working very well and I am looking for alternate methods. What I'm going right now is taking an input command and using
CreateProcess
withcmd /C *command* > outputFile
, then reading the file and displaying the output. However, the problem with this approach is that if I want to start an app, lets say Notepad, I would not be able to do anything else until Notepad closes. As well, the cd command is rendered useless, as when cmd exits and I call another command, the new cmd created byCreateProcess
is still at the same directory. Does anyone have any suggestions for a different approach - perhaps somehow piping the input/output from the cmd window directly to my app? Thanks very much. :) -
Hi All, I am trying to add a cmd functionality into my app, however it's not working very well and I am looking for alternate methods. What I'm going right now is taking an input command and using
CreateProcess
withcmd /C *command* > outputFile
, then reading the file and displaying the output. However, the problem with this approach is that if I want to start an app, lets say Notepad, I would not be able to do anything else until Notepad closes. As well, the cd command is rendered useless, as when cmd exits and I call another command, the new cmd created byCreateProcess
is still at the same directory. Does anyone have any suggestions for a different approach - perhaps somehow piping the input/output from the cmd window directly to my app? Thanks very much. :) -
Hi All, I am trying to add a cmd functionality into my app, however it's not working very well and I am looking for alternate methods. What I'm going right now is taking an input command and using
CreateProcess
withcmd /C *command* > outputFile
, then reading the file and displaying the output. However, the problem with this approach is that if I want to start an app, lets say Notepad, I would not be able to do anything else until Notepad closes. As well, the cd command is rendered useless, as when cmd exits and I call another command, the new cmd created byCreateProcess
is still at the same directory. Does anyone have any suggestions for a different approach - perhaps somehow piping the input/output from the cmd window directly to my app? Thanks very much. :)Have you tried to create console for your process with AllocConsole?
Life is a stage and we are all actors!
-
Have you tried to create console for your process with AllocConsole?
Life is a stage and we are all actors!
No, I haven't because I don't see how would I receive the output of any command with that method. I don't see how I can input stuff into it either...:confused: EDIT: aha, I see now. Going to try it right now. Thanks! :)
modified on Saturday, March 13, 2010 6:40 PM
-
Have you tried to create console for your process with AllocConsole?
Life is a stage and we are all actors!
Okay, that doesn't work either because the only ways I can actually call the command is ShellExecute or system() - they both cannot change the current directory. I'm going to try ShellExecute instead now, I think that might work. Thanks again for your help.
-
Hi All, I am trying to add a cmd functionality into my app, however it's not working very well and I am looking for alternate methods. What I'm going right now is taking an input command and using
CreateProcess
withcmd /C *command* > outputFile
, then reading the file and displaying the output. However, the problem with this approach is that if I want to start an app, lets say Notepad, I would not be able to do anything else until Notepad closes. As well, the cd command is rendered useless, as when cmd exits and I call another command, the new cmd created byCreateProcess
is still at the same directory. Does anyone have any suggestions for a different approach - perhaps somehow piping the input/output from the cmd window directly to my app? Thanks very much. :)Start the command directly but use pipes to redirect it's output. See this[^] article for details. As for telling when the program is done use the process
HANDLE
returned in theLPPROCESS_INFORMATION
structure passed toCreateProcess
. A processHANDLE
can be passed to one of wait functions such asWaitForSingleObject
because it becomes signalled when the process has finished executing. Also note that a common mistake made by people is not to close the process and threadHANDLE
s when they're done with them (or not at all). UseGetExitCodeProcess
to retrieve the return code.Steve