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. how to write to already opened console window

how to write to already opened console window

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
13 Posts 4 Posters 3 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.
  • B Offline
    B Offline
    Bilge Kaan
    wrote on last edited by
    #1

    Hello All, I want to send cmds to previously opened console application for instance ,sending dir cmd to already opened cmd prompt. I got console window handle like below , HWND hwnd = ::FindWindow("ConsoleWindowClass","cmd.exe"); then how to write dir cmd to console? how to retrieve console handle for input and output ?

    T B D 3 Replies Last reply
    0
    • B Bilge Kaan

      Hello All, I want to send cmds to previously opened console application for instance ,sending dir cmd to already opened cmd prompt. I got console window handle like below , HWND hwnd = ::FindWindow("ConsoleWindowClass","cmd.exe"); then how to write dir cmd to console? how to retrieve console handle for input and output ?

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      is it important that is stays visible or do you only want to get the dir command's result ?

      B 1 Reply Last reply
      0
      • T toxcct

        is it important that is stays visible or do you only want to get the dir command's result ?

        B Offline
        B Offline
        Bilge Kaan
        wrote on last edited by
        #3

        not only to get cmd result , i also want to keep it visible.

        1 Reply Last reply
        0
        • B Bilge Kaan

          Hello All, I want to send cmds to previously opened console application for instance ,sending dir cmd to already opened cmd prompt. I got console window handle like below , HWND hwnd = ::FindWindow("ConsoleWindowClass","cmd.exe"); then how to write dir cmd to console? how to retrieve console handle for input and output ?

          B Offline
          B Offline
          Bilge Kaan
          wrote on last edited by
          #4

          not only to get cmd result , i also want to keep it visible.

          B I 2 Replies Last reply
          0
          • B Bilge Kaan

            not only to get cmd result , i also want to keep it visible.

            B Offline
            B Offline
            Bilge Kaan
            wrote on last edited by
            #5

            I found some samples in the net,where they create their own process and create pipe. my problem is i want to write cmd to previously created console window and i dont know how to create pipe to this console

            1 Reply Last reply
            0
            • B Bilge Kaan

              Hello All, I want to send cmds to previously opened console application for instance ,sending dir cmd to already opened cmd prompt. I got console window handle like below , HWND hwnd = ::FindWindow("ConsoleWindowClass","cmd.exe"); then how to write dir cmd to console? how to retrieve console handle for input and output ?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Not sure if it will work, but you might try AttachConsole(), followed by one of the Writexxx() functions. You could easily do this if your program also created the console window.


              "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

              "There is no death, only a change of worlds." - Native American Proverb

              B 1 Reply Last reply
              0
              • D David Crow

                Not sure if it will work, but you might try AttachConsole(), followed by one of the Writexxx() functions. You could easily do this if your program also created the console window.


                "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                "There is no death, only a change of worlds." - Native American Proverb

                B Offline
                B Offline
                Bilge Kaan
                wrote on last edited by
                #7

                but i can only retrieve consolewindow handle ,how I can utilize handle to attachconsole

                D 1 Reply Last reply
                0
                • B Bilge Kaan

                  not only to get cmd result , i also want to keep it visible.

                  I Offline
                  I Offline
                  includeh10
                  wrote on last edited by
                  #8

                  Bilge Kaan, ur post is very interesting. may I ask: (1)what OS do u use for the App? (2)is the console executed (run) by your App? acturally I want to find already opened console window also, but as I tested, the function FindWindow() doesn't work.


                  A special image tool for C++ programmers, don't miss it! The world unique Software Label Maker is here for you and me ... A nice hyper tool for optimizing your MS html-help contents.


                  B 1 Reply Last reply
                  0
                  • I includeh10

                    Bilge Kaan, ur post is very interesting. may I ask: (1)what OS do u use for the App? (2)is the console executed (run) by your App? acturally I want to find already opened console window also, but as I tested, the function FindWindow() doesn't work.


                    A special image tool for C++ programmers, don't miss it! The world unique Software Label Maker is here for you and me ... A nice hyper tool for optimizing your MS html-help contents.


                    B Offline
                    B Offline
                    Bilge Kaan
                    wrote on last edited by
                    #9

                    1 ) I am using Win2000. 2 ) Console is not executed by my application.I want to write cmds to console created by another appli or manually started it is working proper for me , it is want you need HWND hwnd = ::FindWindow("ConsoleWindowClass","console_title");

                    I 1 Reply Last reply
                    0
                    • B Bilge Kaan

                      but i can only retrieve consolewindow handle ,how I can utilize handle to attachconsole

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      Use GetWindowThreadProcessId().


                      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                      "There is no death, only a change of worlds." - Native American Proverb

                      B 1 Reply Last reply
                      0
                      • D David Crow

                        Use GetWindowThreadProcessId().


                        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                        "There is no death, only a change of worlds." - Native American Proverb

                        B Offline
                        B Offline
                        Bilge Kaan
                        wrote on last edited by
                        #11

                        attachconsole is only available for XP and Vista.

                        D 1 Reply Last reply
                        0
                        • B Bilge Kaan

                          attachconsole is only available for XP and Vista.

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #12

                          Bilge Kaan wrote:

                          attachconsole is only available for XP and Vista.

                          It helps to specify those requirements up front.


                          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                          "There is no death, only a change of worlds." - Native American Proverb

                          1 Reply Last reply
                          0
                          • B Bilge Kaan

                            1 ) I am using Win2000. 2 ) Console is not executed by my application.I want to write cmds to console created by another appli or manually started it is working proper for me , it is want you need HWND hwnd = ::FindWindow("ConsoleWindowClass","console_title");

                            I Offline
                            I Offline
                            includeh10
                            wrote on last edited by
                            #13

                            My OS is win98 (develop PCs are using win98 for us). I loaded a dos window, whose title is "MS-DOS Prompt" I tested HWND hwnd = ::FindWindow("ConsoleWindowClass","MS-DOS Prompt"); but return value (hwnd) is zero. what is wrong? did u test your code on win98 or other OS (your users may use different OSs)?


                            A special image tool for C++ programmers, don't miss it! The world unique Software Label Maker is here for you and me ... A nice hyper tool for optimizing your MS html-help contents.


                            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