Results 1 to 12 of 12

Thread: Gedt reult from Command line exe.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,247

    Gedt reult from Command line exe.

    I have a DOS program that runs from the Comamnd line and processes the file added to the name e.g
    D:\Flacs>aucdtect "Track01 (9).wav"
    I could Shell to this from VB6 but would need to wait for the DOS program to finish then somehow capture it's result (which is printed to the console window) and repeat the process for a batch of files.
    Is such a thing possible in VB6 without being overly complicated?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: Gedt reult from Command line exe.

    You can call shell and wait for it to finish, do a quick search for ShellAndWait.

    You could also redirect ( > ) your results to a file instead of on the DOS window, for example:
    Code:
    D:\Flacs>aucdtect "Track01 (9).wav" > "C\some folder\Results.txt"
    Then after the ShellAndWait informs you it's done, read the text file and delete it. Just thinking out loud for an easy-ish solution.

    If running a batch, you can use >> vs > in the redirection. That should append vs create new file.

    Testing the redirection can be done easy enough, before you even look for ShellAndWait examples.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,247

    Re: Gedt reult from Command line exe.

    Thanks again LaVolpe that's a brilliant idea. I'll look for Shell&Wait and see how I go...

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,247

    Re: Gedt reult from Command line exe.

    I found this on a search here but it doesn't work (yet?)
    Code:
    Private Function ShellAndWait(CmdLine As String) As Long
     Dim proc As PROCESS_INFORMATION
     Dim start As STARTUPINFO
     Dim ret&
    
     '
     ' Initialize the STARTUPINFO structure:
     '
     start.cb = Len(start)
     
     '
     ' Start the shelled application:
     '
     ret& = CreateProcessA(0&, CmdLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
     
     If ret = 0 Then
       ShellAndWait = 0
     Else
       '
       ' Wait for the shelled application to finish:
       '
       ret& = WaitForSingleObject(proc.hProcess, INFINITE)
       ret& = CloseHandle(proc.hProcess)
    
       ShellAndWait = 42
     End If
    End Function
    The problem is Line 2 Dim proc As PROCESS_INFORMATION gives UserDefined Type not defined.
    I'm guessing this wants a reference and I've struck this before. Apart from Google, is there a better way to find what reference something wants?
    Also the parameter passed is called "CmdLine". Is this function all you need, and no need for SHELL ?

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: Gedt reult from Command line exe.

    On this forum, an example with a short discussion:
    http://www.vbforums.com/showthread.p...tion-RESOLOVED
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,247

    Re: Gedt reult from Command line exe.

    May have struck a glitch... in that link (which I've changed to) it runs Notepad and continues when notepad is click closed. The program I want isn't closed by clicking, it just ends. Will vb6 know that's happened ?

    Couple of other things, the amendments by Wokawidget uses a boolean in Form_Unload. I don't have a Form. Will DoEvents cause a problem as he describes ? I haven't compiled it yet. Mainly as Results.txt isn't being written.
    So far I have:
    Code:
     Sub test5()
    
        Dim nStart As Date
        Dim a As String
        a = "D:\flac\aucdtect.exe test.wav > C:\Temp\Results.txt"
        nStart = Now
        
        ShellAndWait a, vbNormalFocus, True
        
        MsgBox "You spent " & DateDiff("s", nStart, Now) & _
        " second(s) in notepad.", vbCritical
        
      End Sub
    I did have some errors with the quotes in a (and they may still be wrong).

  7. #7
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,034

    Re: Gedt reult from Command line exe.

    You can try this ShellAndReturnOutput function:

    thinBasic Code:
    1. Option Explicit
    2.  
    3. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    4.  
    5. Private Sub Form_Click()
    6.     Print ShellAndReturnOutput("cmd /c dir")
    7. End Sub
    8.  
    9. Private Function ShellAndReturnOutput(sCommand As String, Optional ByVal UseDoEvents As Boolean) As String
    10.     With CreateObject("WScript.Shell").Exec(sCommand)
    11.         Do While .Status = 0 '--- running
    12.             ShellAndReturnOutput = ShellAndReturnOutput & .StdOut.ReadAll & .StdErr.ReadAll
    13.             If UseDoEvents Then
    14.                 DoEvents
    15.             Else
    16.                 Call Sleep(1)
    17.             End If
    18.         Loop
    19.     End With
    20. End Function
    Unfortunately there is no way to hide the black console of the spawned process using WshScriptExec object. For that you'll need a WshScriptExec replacement class like this cExec.cls which implements StartHidden parameter on its Run method.

    cheers,
    </wqw>

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,053

    Re: Gedt reult from Command line exe.


  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,247

    Re: Gedt reult from Command line exe.

    wqweto, thank you for that code. It certainly nicely returns the directory but I cannot get it to run my file.
    If I go to the DOS window, at the "D:/flac" prompt I type "aucdtect test.wav" and it processes the file and reports a result.
    But I can't emulate that from vb6. aucdtect runs and returns Usage options (like you entered the ext name with no file to process)
    My results are
    Debug.Print ShellAndReturnOutput("D:\Flac aucdtect test.wav") => Access is denied error
    Debug.Print ShellAndReturnOutput("D:\Flac\aucdtect test.wav") => info screen only. Same as ShellAndReturnOutput("D:\Flac\aucdtect")

    Am I doing something wrong?

  10. #10
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,034

    Re: Gedt reult from Command line exe.

    Try this

    ChDir "D:\path\to\test_wav_folder"
    ShellAndReturnOutput("D:\flac\aucdtect.exe test.wav")

    or even better pass the full pathname

    ShellAndReturnOutput("D:\flac\aucdtect.exe D:\path\to\test.wav")

    cheers,
    </wqw>

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,247

    Re: Gedt reult from Command line exe.

    Yes that worked. But the program now takes several minutes to work, as opposed to a few seconds.
    That's if it does finish at all, as the DOS window stayed on screen with an hourglass and I had to close it manually. Then it printed the results
    to the debug window over multiple lines with every line twice). Tried 3 tests of varying durations. None finished or returned to vb.
    So close! Maybe it can be corrected, I don't know. But thanks for your input.

  12. #12
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,034

    Re: Gedt reult from Command line exe.

    Did you try setting the UseDoEvents parameter like this

    ShellAndReturnOutput("D:\flac\aucdtect.exe D:\path\to\test.wav", UseDoEvents:=True)

    cheers,
    </wqw>

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