Link to home
Start Free TrialLog in
Avatar of mernion
mernion

asked on

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 10.0.0.0 -who - me
and shows some output info about that ip, etc..
BUT i have to do test.exe -ip 10.0.0.0 -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
Avatar of PePi
PePi


dim retVal as Double

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


Avatar of mernion

ASKER

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 10.0.0.0 -who - me > temp.txt", vbHide)
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 10.0.0.0 -who - me > temp.txt
ASKER CERTIFIED SOLUTION
Avatar of PePi
PePi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mernion

ASKER

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 10.0.0.0 -who - me > temp.txt", vbHide)
  do...
Shell("C:\temp\test.exe -ip 10.0.0.0 -who - me > C:\TEMP\temp.txt", vbHide)
Avatar of mernion

ASKER

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 10.0.0.0 > c:\text.txt", 1)