I need to invoke an exe from VB. I have to pass some parammeters to run the exe. The exe is giving a 16 digit number as output i need to store the result in a output file.
Is there any feasible solution.
Look at the "Shell" function. The big caveat is that the shelled process runs asynchronously, and the shell call returns immediately, so you need to have a way to know that the shelled process has completed before you try to get results back from it.
One way I've accomplished this is to write to "FILENAME.TMP" during the shelled EXE, and then rename the file to "FILENAME.OUT" as the last thing the shelled EXE does. Then, you just watch for the "FILENAME.OUT" to appear, and you'll know the shelled process has completed. If the shell starts again and finds "FILENAME.OUT" you can either wait for the file to go away, or kill the old file and create a new one.
Of course, there are prettier ways to do it using APIs, but I've used the rename trick for handshaking between asynchronous processes (often to coordinate mainframe and PC applications) in a lot of different circumstances with good success rates, regardless of operating systems, programs, or whatever. Rename is an OS-based function, and it's fast on all types of systems.
If the EXE sends to STDOUT, then pipe to a file, and shell a batch file that does a rename call after the EXE ends.
DEL outfile.out >NUL
MYPROG.EXE inputstring >outfile.tmp
RENAME outfile.tmp outfile.out
the solution i have presented, along with the accompanying forum thread will work fine. post your code and i will take a look.
can u test by creating a vbs file with the following in it
Dim RetVal As Long
Dim WSH As IWshShell
Dim WaitForTermination As Boolean
Dim CommandLine As String
Private Declare Sub ExitProcess Lib "kernel32" (ByVal ReturnCode As Long)
Private Sub Command1_Click()
Dim oFso As New FileSystemObject
Dim oFolder As Folder
Dim ofile As File
Dim str_srcfoldername As String
Dim str_dstfoldername As String
Dim int_totalcount As Integer
Dim int_converted As Integer
Dim int_pgbarunit As Integer
Set WSH = New IWshShell_Class
Open "c:\testing.txt" For Output As #1
str_srcfoldername = c:\inputSet oFolder = oFso.GetFolder(str_srcfoldername)
MsgBox (str_srcfoldername)
For Each ofile In oFolder.Files
Print #1, ofile.Name
WaitForTermination = True
filepath = str_srcfoldername & ofile.Name
i am not that good with VB so i didnt know about the Set WSH = New IWshShell_Class. i will use it in future myself as no doubt it doesnt eat as much memory as what i have done in the past which is...
Set WshShell = CreateObject("WScript.Shell"
Dim RetVal As Long
Dim WSH
Dim WaitForTermination As Boolean
Dim CommandLine As String
Private Declare Sub ExitProcess Lib "kernel32" (ByVal ReturnCode As Long)
Private Sub Command1_Click()
Dim oFso As New FileSystemObject
Dim oFolder As Folder
Dim ofile As File
Dim str_srcfoldername As String
Dim str_dstfoldername As String
Dim int_totalcount As Integer
Dim int_converted As Integer
Dim int_pgbarunit As Integer
Set WshShell = CreateObject("WScript.Shell"
Open "c:\testing.txt" For Output As #1
str_srcfoldername = c:\inputSet oFolder = oFso.GetFolder(str_srcfoldername)
MsgBox (str_srcfoldername)
For Each ofile In oFolder.Files
Print #1, ofile.Name
WaitForTermination = True
filepath = str_srcfoldername & ofile.Name
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.