Results 1 to 10 of 10

Thread: get data from DOS exe

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    France
    Posts
    21

    Question get data from DOS exe

    Hello,

    Can anybody tell me how I could obtain in my VB app what is displayed on the command window by a command line exe.

    The fact is that I am trying to make a GUI for a command line app for my little bro... and I actually need to display some infos in my app since he will not be able to find them out among the lot of lines printed by the dos tool.

    I plan to to use shell() to run the DOS exe.

    Thanks for your help
    Black Rose of the Artist Clan

  2. #2
    Matthew Gates
    Guest
    Here's an example:


    VB Code:
    1. Private Sub Form_Load()
    2.     Shell "command.com /c Dir /b c:\windows > c:\cListing.txt", 0
    3. End Sub

  3. #3
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    you can dump the results of the commands into a file:

    VB Code:
    1. Shell("netstat > log.txt", vbNormalFocus)

    and then read in the file in vb:

    VB Code:
    1. Dim Buffer As String
    2. Dim Temp As String
    3.  
    4. Open "log.txt" For Input As #1
    5.  
    6. Do Until EOF(1)
    7.      Input #1, Temp
    8.      Buffer = Buffer & Temp
    9. Loop

    and then kill the file:

    VB Code:
    1. Kill "log.txt"

    hope this helps
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You can redirect the output to a file and then parse that file for the information you need.
    Unfortunatly you can't simply use the > character from Windows to redirect to file so the solution is to have your app create a BAT file and shell that.
    Code:
    Public Sub ShellIt(ByVal AppToShell As String, ByVal RedirectTo As String)
        Dim hFile As Integer
        Dim sBatFile As String
    
        sBatFile = Environ("Temp")
        sBatFile = sBatFile & IIf(Right$(sBatFile, 1) <> "\", "\tmpBat.Bat", "tmpBat.Bat")
        hFile = FreeFile
        Open sBatFile For Output As #hFile
        Print #hFile, "@" & AppToShell & " >" & RedirectTo
        Close #hFile
        Shell sBatFile, vbHide
    End Sub
    You call the above procedure like this:
    Code:
    ShellIt "c:\TheDosApp.exe", "c:\Output.txt"
    After that simply parse the Output.txt file and show whatever information you want from it.

    Best regards

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    France
    Posts
    21

    Waouh !

    3 answers in less than an hour !
    that's that fast !

    thank you very much !

    Matthew Gates> can you explain me what is this ,0 at the end of
    Shell "command.com /c Dir /b c:\windows > c:\cListing.txt", 0
    I thought it was just shell "myapp.exe"
    And, as Iam a newbie at DOS, could you explain me the details of the command line ?
    Black Rose of the Artist Clan

  6. #6
    ~~~
    Guest
    Ok.

    You've got a dos program called myapp.exe that displays lots of info when run.

    To get that info you have to redirect the text to a file. This is done by running the program as "myapp.exe > c:\somefile.txt". This can be done using the Shell statement as:

    Shell "c:\myapp.exe > c:\somefile.txt"

    After this , read the file c:\somefile.txt into your program with some code like this :

    dim strText as string
    Open "c:\somefile.txt" for input as #1
    strtext = input(1,lof(1))
    close #1

    That's it. You now have all the text displayed by the Dos program in a variable.

  7. #7
    Matthew Gates
    Guest

    Re: Waouh !

    Originally posted by ciler
    3 answers in less than an hour !
    that's that fast !

    thank you very much !

    Matthew Gates> can you explain me what is this ,0 at the end of
    Shell "command.com /c Dir /b c:\windows > c:\cListing.txt", 0
    I thought it was just shell "myapp.exe"
    And, as Iam a newbie at DOS, could you explain me the details of the command line ?

    The 0 is to hide the DOS window. It can be 0 or vbHide.
    The Shell function can be used to launch COM and BAT files as well.

    Command.com <-MS-DOS
    /c <- Executes the specified command and returns.
    Dir <-specifies files and folders in a directory
    /b <-uses bare format (no heading or summary)
    > <-Output to file
    c:\cListing.txt <-file the information was written to
    , 0 <-vbHide - hides the MS-DOS window, you can change this to 1 or vbNormalFocus if you wish to see the DOS Window.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    France
    Posts
    21

    Unhappy :( It don't works ...

    I tried to use the > dos command, it creates a text file, but the file is empty
    (either in dos mode or with VB and shell)

    Here is my code :
    c:\TestDir\normalize.exe -o test.wav jenina.wav > log.txt

    (syntax for normalize is : normalize -o <file> input-file)

    I can't figure what I did wrong ?
    Thanks for any help
    Black Rose of the Artist Clan

  9. #9
    ~~~
    Guest
    Does the program prompt you to enter any information when run normally ?

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    France
    Posts
    21

    wooops !

    Yep, now it works !

    And btw I know that it is useless trying to read the file while the process (here normalize) is still working...

    Thank you for your help !
    Black Rose of the Artist Clan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width