Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Detect Completed Batch Job Before Writing File

Status
Not open for further replies.

BootMeUp

MIS
May 31, 2000
35
US
My code is running command line DOS from a batch file and producing text file
output. The command needs be done before the text file is rewritten (else, user
gets old message). I'm using GetNumTasks function to test for this. Error occurs
at "Num_Apps = GetNumTasks()". The message is: "Run-Time error '53'; File not
found:Kernel".
Below is code:
====================================================
Private Declare Function GetNumTasks Lib "Kernel" () As Integer

Private Sub Command1_Click()
Dim Num_Apps As Integer, NewFile As Integer
Dim File_Data As String, DosCmd As String
Dim X As Integer
'Create a batch file with the DIR *.EXE command
'and redirect the output to a textfile DIRLIST.TXT.
DosCmd = "DIR c:\*.* > c:\DIRLIST.DAT"
NewFile = FreeFile
Open "C:\DIRBAT.BAT" For Output As #NewFile
Print #NewFile, DosCmd
Close #NewFile
'Call the Shell command to execute DIRBAT.BAT.
==>Num_Apps = GetNumTasks() <===========This is where error
occurs
X = Shell(&quot;C:\DIRBAT.BAT&quot;, 2)
'Wait until DIR has finished doing its thing.
Do While GetNumTasks() <> Num_Apps
X = DoEvents()
Loop
'Display the filenames in the Text Box.
NewFile = FreeFile
Open &quot;C:\DIRLIST.DAT&quot; For Input As #NewFile
Text1.Text = &quot;&quot;
While Not EOF(NewFile)
Line Input #NewFile, File_Data
Text1.Text = Text1.Text & File_Data & Chr(13) & Chr(10)
Wend
Close #NewFile
End Sub
Private Sub Command2_Click()
End
End Sub
====================================================
This program was used as a test base for other programs
which perform command line processing.
=====================================================
Any help will be appreciated
Steve A. [sig][/sig]
 
If your code is starting batch files and the batch file is writing another file, halt the vb code until the batch file has finished running, instead of using GetNumTasks. [sig]<p>Simon<br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top