Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Aug 2005
    Location
    Needham, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Shell Redirect doesn't work (EN/VB 6.5)

    All,

    Here is a fragment of VBA code running under Excel whose purpose is to execute the text2pcap program (from Wireshark.org), which it does.

    sInputPath = sPath
    iX = InStrRev(sPath, ".") ' Find the file extension separator
    sOutputPath = Left(sPath, iX) & "pcap"
    ' Now quote the paths as CMD.exe can't handle embedded spaces
    sInputPath = sQt & sInputPath & sQt
    sOutputPath = sQt & sOutputPath & sQt
    sArgs = sArgs & " " & sInputPath & " " & sOutputPath & " 2>C:WINDOWSTempstderr.txt"
    vTaskID = Shell("text2pcap" & sArgs, vbNormalNoFocus)

    The problem is that though it actually calls text2pcap and prodduces the output, it does not redirect Stderr to the file stderr.txt. If I set a break at the last line and copy sArgs and then paste it into the CMD box, I do get a stderr.txt. Does running a dos program under shell redefine the handles or the like? I tried using a 3> redirect and still got nothing.

    Thanks,

    sonoflawrence

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Shell Redirect doesn't work (EN/VB 6.5)

    Have you tried a Shell instruction with a literal string instead of a variable filled by concatenating bits and pieces? If so, does that work as intended?

    (And a belated welcome to Woody's Lounge, by the way)

  3. #3
    New Lounger
    Join Date
    Aug 2005
    Location
    Needham, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shell Redirect doesn't work (EN/VB 6.5)

    Hello HansV

    Yes, I tried several variations on the theme, even varying the Handle # in the assumption that the Shell environment renumbered them.


    The good news is that I have a solution. I can't give an exact snippet since I am away from the office, but this DOES WORK!

    Shell (cmd /c arguments 2>stderr_file, vbHide)

    I suppose that shelling cmd.exe allows it to run an app. in a comfortable environment.

    On a more personal note, I have many times found whati needed in the various forums over a few years, so I never felt moved to post before. This is, I hope, a tribute to the breadth and depth of solutions and answers contained in these forums.

    sonoflawrence

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Shell Redirect doesn't work (EN/VB 6.5)

    I'm glad you found a solution.
    Thanks for your kind words!

  5. #5
    New Lounger
    Join Date
    Aug 2005
    Location
    Needham, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shell Redirect doesn't work (EN/VB 6.5)

    Hans,

    You are very welcome. BTW, I shouldn't post after 6 PM due to the flagging of my braim cells. I failed to quote the call to cmd.exe and the /C switch. If you need to see what is going on for debugging purposes, use a /K switch, thus:

    vTaskID = Shell("cmd /K" & sBat, vbNormalFocus) where sBat is all of the arguments. In my case it was a call to text2pcap and all of its arguments.

    Cmd.exe actually recognizes quite a few switches. Try this in a DOS box: >cmd /?

    Cheers,

    Sonof lawrence

Posting Permissions

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