|
From: Bu on 19 Jan 2008 17:59 Hello, I want to run from a VB6 program an old DOS program. The DOS program displays some information on the screen. One parameter (filename) is given to the DOS program on the command line. For this i use the VB6 'Shell' command with in a string: path/filename of the DOS program, a pipe to a tempory file (to catch the screen info), and the the filename. After the program runs i can process the DOS screen information i piped to the tempory file in the VB6 program. Sometimes this works and sometimes not. I believe the reason is that the DOS program has not finished yet while the VB program carries on. I am a little bit confused with the information given on the internet about waiting to continue after the shell program has finished executing. Can somebody tell me how i can wait till the DOS program finishes?
From: MikeD on 19 Jan 2008 18:12 "Bu" <si(a)si.si> wrote in message news:n7v4p3hloldlkdm1egohf1l3ucf9jdbho6(a)4ax.com... > Hello, > I want to run from a VB6 program an old DOS program. > The DOS program displays some information on the screen. One parameter > (filename) is given to the DOS program on the command line. > For this i use the VB6 'Shell' command with in a string: path/filename > of the DOS program, a pipe to a tempory file (to catch the screen > info), and the the filename. > After the program runs i can process the DOS screen information i > piped to the tempory file in the VB6 program. > Sometimes this works and sometimes not. > I believe the reason is that the DOS program has not finished yet > while the VB program carries on. > I am a little bit confused with the information given on the internet > about waiting to continue after the shell program has finished > executing. > Can somebody tell me how i can wait till the DOS program finishes? Being a DOS program, I supposed what I'd do is create a batch file that runs the DOS program (and your VB app would run that batch file). In the batch file, use the Start command, which has a /wait parameter. If you provide more information/details, you might get a better answer/solution. -- Mike Microsoft MVP Visual Basic
From: Bob Riemersma on 19 Jan 2008 21:13 Ahh, but what waits for the batch file to end? No, I'd look for any of hundreds of articles on the web about "Shell and wait" in VB, or the more advanced "Shell with Pipe" technique that allows your VB program to interact with a command-line Standard I/O stream program instead of redirecting output to a disk file. The latter works, but doesn't permit interaction. "MikeD" <nobody(a)nowhere.edu> wrote in message news:e3H$CDvWIHA.5208(a)TK2MSFTNGP04.phx.gbl... > > Being a DOS program, I supposed what I'd do is create a batch file that > runs the DOS program (and your VB app would run that batch file). In the > batch file, use the Start command, which has a /wait parameter. > > If you provide more information/details, you might get a better > answer/solution. > > -- > Mike > Microsoft MVP Visual Basic
From: Bill Plenge on 20 Jan 2008 10:28 Bu wrote: > Hello, > I want to run from a VB6 program an old DOS program. > The DOS program displays some information on the screen. One parameter > (filename) is given to the DOS program on the command line. > For this i use the VB6 'Shell' command with in a string: path/filename > of the DOS program, a pipe to a tempory file (to catch the screen > info), and the the filename. > After the program runs i can process the DOS screen information i > piped to the tempory file in the VB6 program. > Sometimes this works and sometimes not. > I believe the reason is that the DOS program has not finished yet > while the VB program carries on. > I am a little bit confused with the information given on the internet > about waiting to continue after the shell program has finished > executing. > Can somebody tell me how i can wait till the DOS program finishes? When you're producing an output file that you know the full path/name of, one technique I've used successfully in the past is to attempt to open the output file for input or binary access with exclusive rights. If the attempt fails I know the program isn't finished creating it, so I pause a bit then try it again. If the attempt succeeds I know the other program finished its processing and just close it and continue on to with my codes processing.. Hope this helps. Best, Bill
From: Ralph on 20 Jan 2008 10:59 "Bu" <si(a)si.si> wrote in message news:n7v4p3hloldlkdm1egohf1l3ucf9jdbho6(a)4ax.com... > Hello, > I want to run from a VB6 program an old DOS program. > The DOS program displays some information on the screen. One parameter > (filename) is given to the DOS program on the command line. > For this i use the VB6 'Shell' command with in a string: path/filename > of the DOS program, a pipe to a tempory file (to catch the screen > info), and the the filename. > After the program runs i can process the DOS screen information i > piped to the tempory file in the VB6 program. > Sometimes this works and sometimes not. > I believe the reason is that the DOS program has not finished yet > while the VB program carries on. > I am a little bit confused with the information given on the internet > about waiting to continue after the shell program has finished > executing. > Can somebody tell me how i can wait till the DOS program finishes? > Just to add to the pile, you can also just wait for the file to become available. Private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4 Private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2 Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1 Private Const FILE_NOTIFY_CHANGE_SIZE = &H8 Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10 Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100 Private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100 Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long Private Declare Function FindCloseChangeNotification Lib "kernel32" ( ByVal hChangeHandle As Long) As Long Private Declare Function FindNextChangeNotification Lib "kernel32" ( ByVal hChangeHandle As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" ( ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function ResetEvent Lib "kernel32" ( ByVal hEvent As Long) As Long Public Sub WaitForFileChange(ByVal sFolder as String, Optional ByVal nFilter = FILE_NOTIFY_CHANGE_ALL, Optional ByVal bSubDir As Boolean = TRUE, Optional ByVal TimeOut As Long = -1) Dim hHook As Long ' set the hook hHook = FindFirstChangeNotification(sFolder, bSubDir, nFilter) ' wait for a strike WaitForSingleObject hHook, TimeOut ' got it so put the rod away FindCloseChangeNotification hHook End Sub IMHO, if the launched app is short-lived and the return relatively small, use Bob's suggestions. If the app involves user intervention and may hang around for awhile and the return requires a file use the above. -ralph
|
Next
|
Last
Pages: 1 2 Prev: DLL Error Next: Help Help$$ modifying the recorded (VBA) Macro with Excel manual Process |