Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. "Virtual" Command Prompt

"Virtual" Command Prompt

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hxhl95
    wrote on last edited by
    #1

    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 with cmd /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 by CreateProcess 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. :)

    H L S 3 Replies Last reply
    0
    • H hxhl95

      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 with cmd /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 by CreateProcess 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. :)

      H Offline
      H Offline
      hxhl95
      wrote on last edited by
      #2

      Oh, and I can't distinguish between a successful command and an unsuccessful one (whether that command even exists or not).

      1 Reply Last reply
      0
      • H hxhl95

        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 with cmd /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 by CreateProcess 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. :)

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Have you tried to create console for your process with AllocConsole?

        Life is a stage and we are all actors!

        H 2 Replies Last reply
        0
        • L Lost User

          Have you tried to create console for your process with AllocConsole?

          Life is a stage and we are all actors!

          H Offline
          H Offline
          hxhl95
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • L Lost User

            Have you tried to create console for your process with AllocConsole?

            Life is a stage and we are all actors!

            H Offline
            H Offline
            hxhl95
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • H hxhl95

              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 with cmd /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 by CreateProcess 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. :)

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              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 the LPPROCESS_INFORMATION structure passed to CreateProcess. A process HANDLE can be passed to one of wait functions such as WaitForSingleObject 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 thread HANDLEs when they're done with them (or not at all). Use GetExitCodeProcess to retrieve the return code.

              Steve

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups