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. Visual Basic
  4. catching string from DOS shell

catching string from DOS shell

Scheduled Pinned Locked Moved Visual Basic
linuxquestion
8 Posts 2 Posters 1 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.
  • M Offline
    M Offline
    mohith
    wrote on last edited by
    #1

    hi everyone.. does anyone know if there is a way of getting input from DOS shell. I am running an executable (DOS based program) which prints stuff on the screen. is there a way of catching this from a VB program while the executable is running? please do let me know.. thanks Mohith ;) be the change that you want to see in the world

    J 1 Reply Last reply
    0
    • M mohith

      hi everyone.. does anyone know if there is a way of getting input from DOS shell. I am running an executable (DOS based program) which prints stuff on the screen. is there a way of catching this from a VB program while the executable is running? please do let me know.. thanks Mohith ;) be the change that you want to see in the world

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #2

      The easiest way I know of is to have the standard output (STDOUT) redirected to a text file. You could use some console functions or the ReadFile() API, but that involves more work on your part. Anway, to be able to have the output in VB use the ShellExecute() API.

      Private Const SW_HIDE = 0

      Private Declare Function ShellExecute Lib "shell32.dll" _
      Alias "ShellExecuteA" (ByVal hwnd As Long, _
      ByVal lpOperation As String, ByVal lpFile As String, _
      ByVal lpParameters As String, ByVal lpDirectory As String, _
      ByVal nShowCmd As Long) As Long

      Then, call your exe make sure to redirect the output in the parameter parameter.

      ShellExecute Me.hwnd, "open", "my.exe", "> output.txt", "C:\", SW_HIDE

      The program's output will be in output.txt, which will reside in the same dir as the exe you called. Good luck, Jeremy L. Falcon "The One Who Said, 'The One Who Said...'"

      M 1 Reply Last reply
      0
      • J Jeremy Falcon

        The easiest way I know of is to have the standard output (STDOUT) redirected to a text file. You could use some console functions or the ReadFile() API, but that involves more work on your part. Anway, to be able to have the output in VB use the ShellExecute() API.

        Private Const SW_HIDE = 0

        Private Declare Function ShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" (ByVal hwnd As Long, _
        ByVal lpOperation As String, ByVal lpFile As String, _
        ByVal lpParameters As String, ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) As Long

        Then, call your exe make sure to redirect the output in the parameter parameter.

        ShellExecute Me.hwnd, "open", "my.exe", "> output.txt", "C:\", SW_HIDE

        The program's output will be in output.txt, which will reside in the same dir as the exe you called. Good luck, Jeremy L. Falcon "The One Who Said, 'The One Who Said...'"

        M Offline
        M Offline
        mohith
        wrote on last edited by
        #3

        how does this work? does it write to output.txt in c:\ directory? its not creating the file. its not in the same directory as exe as well. i want to read the output on screen into my VB program. can i do that? i am using VB 6. so i run an executable file from my VB application. that eecutable basically dumps some stuff on to the screen and i want to catch these dumps and show them in my VB application while the executable is running. i dont want to redirect the whole output to a file and then read it in once executable is finished running. can i do this? please let me know. i would really appreciate your help. kindest regards Mohith ;) be the change that you want to see in the world

        J 1 Reply Last reply
        0
        • M mohith

          how does this work? does it write to output.txt in c:\ directory? its not creating the file. its not in the same directory as exe as well. i want to read the output on screen into my VB program. can i do that? i am using VB 6. so i run an executable file from my VB application. that eecutable basically dumps some stuff on to the screen and i want to catch these dumps and show them in my VB application while the executable is running. i dont want to redirect the whole output to a file and then read it in once executable is finished running. can i do this? please let me know. i would really appreciate your help. kindest regards Mohith ;) be the change that you want to see in the world

          J Offline
          J Offline
          Jeremy Falcon
          wrote on last edited by
          #4

          This does work. How are you attempting to implement this? Remember the function and constant are declared with private scope. Change it to public if you put it in a module. Also, I'm assuming you changed my.exe to a filename that exists in your C:\ directory?? Jeremy L. Falcon "The One Who Said, 'The One Who Said...'" Homepage: imputek.com

          M 1 Reply Last reply
          0
          • J Jeremy Falcon

            This does work. How are you attempting to implement this? Remember the function and constant are declared with private scope. Change it to public if you put it in a module. Also, I'm assuming you changed my.exe to a filename that exists in your C:\ directory?? Jeremy L. Falcon "The One Who Said, 'The One Who Said...'" Homepage: imputek.com

            M Offline
            M Offline
            mohith
            wrote on last edited by
            #5

            this is the code in my form ShellExecute Me.hwnd, "open", "hiplex.exe", "> output.txt", "C:\", SW_HIDE and i have made everything public in module which is Public Const SW_HIDE = 0 Public Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, _ ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long still creates no output.txt in c:\. do i need to include anything else? once it creates, how would i read in the stuff from file (output.txt) to lets say a text box within my VB application while the executable is still running? regards Mohith ;) be the change that you want to see in the world

            J 1 Reply Last reply
            0
            • M mohith

              this is the code in my form ShellExecute Me.hwnd, "open", "hiplex.exe", "> output.txt", "C:\", SW_HIDE and i have made everything public in module which is Public Const SW_HIDE = 0 Public Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, _ ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long still creates no output.txt in c:\. do i need to include anything else? once it creates, how would i read in the stuff from file (output.txt) to lets say a text box within my VB application while the executable is still running? regards Mohith ;) be the change that you want to see in the world

              J Offline
              J Offline
              Jeremy Falcon
              wrote on last edited by
              #6

              We'll I'll be! I did run an exe (before I posted) and redirected the output to a file just to make sure and it worked, but I tested it in VB and sure enough it didn't happen. It *does* work, but the catch is you have to have the console open, and it must stay open. If I run a console program outside of an open shell (command) window it closes before STDOUT has time to be written to. So, I tried several things. This involved me actually piping a char stream to my app directly (skipping output.txt). That worked, but it still didn't allow me to make sure the Window was hidden. So, I got the idea to use a batch file. Lo and behold it did the job. No window and output.txt was there. This is because (I assume) of the way a batch file is handled -- it was an execution on top of an execution. The only thing left to do was make sure the program waited long enough to let the text file be created. So, I checked to make sure the process terminates. Posting the code in this message isn't sensible because I also created a simple C console application that prints to STDOUT and an example batch file to run it. So, I ZIPped up the project and posted it for download on my (soon to be) website. Just scan for viruses as a precaution. I'm paranoid about this ever since I got CIH (back in the day). Oh, and don't forget to put myprog.exe and myprog.bat in your C:\ directory. File: http://dev.imputek.com/StdOut.zip Jeremy L. Falcon "The One Who Said, 'The One Who Said...'" Homepage: imputek.com

              M 1 Reply Last reply
              0
              • J Jeremy Falcon

                We'll I'll be! I did run an exe (before I posted) and redirected the output to a file just to make sure and it worked, but I tested it in VB and sure enough it didn't happen. It *does* work, but the catch is you have to have the console open, and it must stay open. If I run a console program outside of an open shell (command) window it closes before STDOUT has time to be written to. So, I tried several things. This involved me actually piping a char stream to my app directly (skipping output.txt). That worked, but it still didn't allow me to make sure the Window was hidden. So, I got the idea to use a batch file. Lo and behold it did the job. No window and output.txt was there. This is because (I assume) of the way a batch file is handled -- it was an execution on top of an execution. The only thing left to do was make sure the program waited long enough to let the text file be created. So, I checked to make sure the process terminates. Posting the code in this message isn't sensible because I also created a simple C console application that prints to STDOUT and an example batch file to run it. So, I ZIPped up the project and posted it for download on my (soon to be) website. Just scan for viruses as a precaution. I'm paranoid about this ever since I got CIH (back in the day). Oh, and don't forget to put myprog.exe and myprog.bat in your C:\ directory. File: http://dev.imputek.com/StdOut.zip Jeremy L. Falcon "The One Who Said, 'The One Who Said...'" Homepage: imputek.com

                M Offline
                M Offline
                mohith
                wrote on last edited by
                #7

                hi Jeremy thanks for this but this reads in from the file once the application (exe) is finished. i want to catch the stuff while the application is still running. is this possible? while the exe is running and sending stuff to screen, i want to catch the output written on screen and print it in the text box. please let me know if this is possible. kind regards Mohith ;) be the change that you want to see in the world

                J 1 Reply Last reply
                0
                • M mohith

                  hi Jeremy thanks for this but this reads in from the file once the application (exe) is finished. i want to catch the stuff while the application is still running. is this possible? while the exe is running and sending stuff to screen, i want to catch the output written on screen and print it in the text box. please let me know if this is possible. kind regards Mohith ;) be the change that you want to see in the world

                  J Offline
                  J Offline
                  Jeremy Falcon
                  wrote on last edited by
                  #8

                  It's possible, but it won't be easy. This will involve you controlling the process and the process' console manually -- which takes some work. If you have MSDN installed, check out... mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2001JAN\1033\fileio.chm::/hh/winbase/conchar_4p6c.htm And look into "Using the Console" and "Console Reference". If you don't have MSDN installed, then you can look at MSDN Online. Jeremy L. Falcon "The One Who Said, 'The One Who Said...'" Homepage: imputek.com

                  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