• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1152
  • Last Modified:

Execute another program through VB and save output

Hello. I have a problem and since i haven't used VB for a while i can't think of a way to do it.

I have a file in c:\temp which is called test.exe and is a command line program that is run like that:
test.exe -ip -who - me
and shows some output info about that ip, etc..
BUT i have to do test.exe -ip -who - me >temp.txt in order to save the output in a temp.txt file (that is what i want and not an visual output)
what i want to do is to make a VB (exe) file which will run every 10 minutes (i have managed to do that) and will execute the above thing (the one with the >temp.txt) and save the output of the test.exe in a file..
I am using VB6 and i can't think of how..
thanks in advance
1 Solution

dim retVal as Double

retVal = Shell("C:\temp\test.exe -ip -who - me > temp.txt", vbHide)

mernionAuthor Commented:
I have done that but it won't work.. it launces the test.exe but it doesn't create the temp.txt file.. I used vbmaximizedfocus in order to see that the program is launched and it is.. why is it not creating the temp.txt file thought?
try using ChDir first

ChDrive "C:\"
ChDir "C:\Temp"
retVal = Shell("C:\temp\test.exe -ip -who - me > temp.txt", vbHide)
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

try creating a batch file and then launch the batch file like

Shell Environ("COMSPEC") & " /C C:\Temp\test.bat"

batch file should contain:

@echo off
cd c:\temp
test.exe -ip -who - me > temp.txt
or you can try this:

Shell "cmd /C /A c:\temp\test.exe -ip -who -me > c:\temp\temp.txt"
mernionAuthor Commented:
none of this works.. have you tried them b4 telling me or have you found them on the net? if they are working for you, then something is wrong with my VB. Just for the case, the one with the bat file: it runs the bat, but no temp.txt is created. If i run the bat by double clicking or from start>run it works perfectly!
Any other solutions?
mernion - Did you try putting the full pathspec on the output redirection?  If you just do ... -me > temp.txt it will show up in the vb app's current default folder.  Make sure you put the whole path that you expect the output to be in.

  instead of
Shell("C:\temp\test.exe -ip -who - me > temp.txt", vbHide)
Shell("C:\temp\test.exe -ip -who - me > C:\TEMP\temp.txt", vbHide)
mernionAuthor Commented:
Even though it didn't work, i will accept PePi's answer because is the closest to which i finally found to work which is this:

x = Shell("cmd.exe /c test.exe -ip > c:\text.txt", 1)

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now