Announcement

Collapse
No announcement yet.

Shell Console Handle

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shell Console Handle

    When I SHELL to a DOS program, how can I get the console handle
    of the window in which the DOS program is running?
    May be simple, but I can't find the way.

    my code:
    ProcessId??? = SHELL("mydosapp.exe")


    Is the ProcessId??? the handle I need?
    Thanks

  • #2
    Originally posted by Emanuele Colombo View Post
    When I SHELL to a DOS program, how can I get the console handle
    of the window in which the DOS program is running?
    May be simple, but I can't find the way.

    my code:
    ProcessId??? = SHELL("mydosapp.exe")


    Is the ProcessId??? the handle I need?
    Thanks
    Can you describe what you want to DO with the handle/window?

    Comment


    • #3
      As John said above, it would be nice to know the context.

      This thread http://www.powerbasic.com/support/pb...hlight=console might help - depending upon what you are aiming at....

      Comment


      • #4
        What do you want, the console output of the child program?

        If so, all you need to do is redirect the STDOUT of the child program to a disk file. If you need to pump in responses, redirect STDIN of the child process to a file you create.

        If you don't feel like doing it the right way (via setting handles and using CreateProcess()) (and I know there is at least one example here of this) you can jus totally wimp out and use the command shell..

        Code:
        SHELL "cmd /c   programname <stdin_file_name >stdout_file_name"
        FWIW, using CreateProcess() you can also specify the size and location of the child process' console.

        Or for that matter, use your own console as the child process' console. (this is tricky, save that for later).
        Last edited by Michael Mattias; 3 Feb 2009, 03:03 PM.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          What I need to do is manipulate the child console at the run time.
          Here the essential code:

          Code:
          #COMPILE EXE
          #DIM ALL
          GLOBAL  MyCondition AS LONG
          
          FUNCTION PBMAIN () AS LONG
              DIM ProcessID   AS DWORD
              DIM hWnd        AS DWORD
              
              ProcessID=SHELL("mydosapp.exe")
              
              DO
                  SLEEP 1
                  SELECT CASE MyCondition
                  CASE 1
                      ShowWindow hWnd, %SW_MINIMIZE   'How can I know hWnd of my "child" console?
                  CASE 2
                      ShowWindow hWnd, %SW_MAXIMIZE
                  CASE ELSE
                      '......
                  END IF
              LOOP
          END FUNCTION
          Is this possible in any way?
          Thanks!

          Comment


          • #6
            You can get the console window (and capture its output if you so desire) by emuerating the windows, but you have to identify the window you want using the window title and/or classname. This example may help: http://www.powerbasic.com/support/pb...ad.php?t=37868

            Comment


            • #7
              > ("mydosapp.exe")

              I don't know you can manipulate an MS-DOS application, except if that MS-DOS application is using STDIN/STDOUT.

              Unless you just mean, "bring up my MS-DOS screen as something which looks like a control on my main screen and let me key stuff in and get responses." If that MS-DOS application does screen painting and has a non-console-type user-interface you might consider migrating that app to PB/CC; if that child process is a Windows' application I think you would have a fighting chance of pulling this off.

              Then again, why don't you describe what this MS-DOS application expects in terms of user input and provides as information? Maybe there is 'another way' which would NOT require a handle to the Command shell's console window.


              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                What I'm trying to do is an "intermediate step" in the process of migration from PB DOS to PBCC, and what I need to do, at the moment, is to switch ON and OFF the console windows that contains my old DOS app. This application uses graphics, text and serial communications....so I can't figure nothing worst.
                I think the best way is to enumerate all the windows and get the handle of the console "by name".
                I thought that ProcessID??? returned by SHELL function was useful for get in some way the handle of the console...
                Thank you for your help.

                Comment


                • #9
                  I thought that ProcessID??? returned by SHELL function was useful for get in some way the handle of the console
                  Well, no, it gives you a process ID.

                  From that you can get a handle to the STDOUT of the child process, and handles to all its top-level aad child windows, but when running MS-DOS appplications the process ID and handles may be to CMD.EXE rather than the MS-DOS program... not that a 'handle' to an MS-DOS process would do you that much good, since there is no way to talk to the program unless it is a cooperating application.

                  Since all these programs are yours, there has got to be a way to make them cooperate... except I'm not sure you want to put that much energy into the task since the programs are already scheduled for a Windows' upgrade anyway.

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X