EEA-Hove
asked on
Use VB.NET to schedule DOS batch process
I need to run a dos batch process every 6 minutes - 8am Monday to 1800 Friday.
Within the (S999.BAT) batch file is 3 vb progs & an exec of FTP.
The process merges up to 20 files then checks to see that all records
are identical. Converts the merged audit file to html & FTP's the
page to the website.
The batch file -
mergeaudit C:\111\001\tempin1.txt C:\T111x001\mergeaudit.txt Y
mergeaudit C:\111\002\tempin1.txt C:\T111x001\mergeaudit.txt N
mergeaudit C:\111\003\tempin1.txt C:\T111x001\mergeaudit.txt N
mergeaudit C:\111\004\tempin1.txt C:\T111x001\mergeaudit.txt N
mergeaudit C:\111\005\tempin1.txt C:\T111x001\mergeaudit.txt N
.... up to 20 files
12checkaudit C:\T111x001\ T111x001
htmlgenc T111x001 _chkaudit.txt audit.html
FTP -i -s:ftpscript.txt
Run manually the batch file process works great.
I would like to execute this S999.BAT file scheduled as a VB.NET process.
I am not sure if I am even using the right processes as I have been doing
VB.NET very long.
This is a work in progress but so far I set the OKtorun flag on 1 minute
before the process start. Try to start the process and immediately turn
the flag off until the next schedule time.
The CMD exe window does open but does not execute any command!
I am sure there is a better way of doing this. Any help is appreciated.
Imports System
Imports System.IO
Imports System.Text
Imports System.Threading
Imports System.Diagnostics
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim OKtoRun As Boolean = False
Dim number As Integer
Dim moment As DateTime = DateTime.Now
Dim minute As String = moment.Minute
number = 1
If OKtoRun = False Then
If moment.Minute = "12" Then
OKtoRun = True
End If
If moment.Minute = "18" Then
OKtoRun = True
End If
End If
If OKtoRun = True Then
If moment.Minute = "11" Then
System.Diagnostics.Process .Start("C: \xxx\S999. bat")
OKtoRun = False
End If
If moment.Minute = "12" Then
System.Diagnostics.Process .Start("C: \xxx\S999. bat")
OKtoRun = False
End If
End If
Catch ex As IOException
MsgBox(ex.ToString)
End Try
End Sub
End Class
Within the (S999.BAT) batch file is 3 vb progs & an exec of FTP.
The process merges up to 20 files then checks to see that all records
are identical. Converts the merged audit file to html & FTP's the
page to the website.
The batch file -
mergeaudit C:\111\001\tempin1.txt C:\T111x001\mergeaudit.txt
mergeaudit C:\111\002\tempin1.txt C:\T111x001\mergeaudit.txt
mergeaudit C:\111\003\tempin1.txt C:\T111x001\mergeaudit.txt
mergeaudit C:\111\004\tempin1.txt C:\T111x001\mergeaudit.txt
mergeaudit C:\111\005\tempin1.txt C:\T111x001\mergeaudit.txt
.... up to 20 files
12checkaudit C:\T111x001\ T111x001
htmlgenc T111x001 _chkaudit.txt audit.html
FTP -i -s:ftpscript.txt
Run manually the batch file process works great.
I would like to execute this S999.BAT file scheduled as a VB.NET process.
I am not sure if I am even using the right processes as I have been doing
VB.NET very long.
This is a work in progress but so far I set the OKtorun flag on 1 minute
before the process start. Try to start the process and immediately turn
the flag off until the next schedule time.
The CMD exe window does open but does not execute any command!
I am sure there is a better way of doing this. Any help is appreciated.
Imports System
Imports System.IO
Imports System.Text
Imports System.Threading
Imports System.Diagnostics
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim OKtoRun As Boolean = False
Dim number As Integer
Dim moment As DateTime = DateTime.Now
Dim minute As String = moment.Minute
number = 1
If OKtoRun = False Then
If moment.Minute = "12" Then
OKtoRun = True
End If
If moment.Minute = "18" Then
OKtoRun = True
End If
End If
If OKtoRun = True Then
If moment.Minute = "11" Then
System.Diagnostics.Process
OKtoRun = False
End If
If moment.Minute = "12" Then
System.Diagnostics.Process
OKtoRun = False
End If
End If
Catch ex As IOException
MsgBox(ex.ToString)
End Try
End Sub
End Class
This sounds more like, you need to create a windows service using multiple timers. Here is somewhat of a background on it http://www.codeguru.com/vb/gen/vb_system/services/article.php/c4825/Creating-a-Windows-Service-in-VBNET.htm
ASKER
Thanks Blue Yonder. I will look at it some more, but it is looking it a bit over my head!
If this is in Windows, you could just use the Task Scheduler to run the batch file.
ASKER
Thanks Seaton007 but the Task scheduler is not that flexible. The batch file will be running 240 times a day.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The repetiton of running a BAT file every 6 minutes for 4 and half days was too much for Windows task scheduler. pycron does it accurately, and with a few clicks of the mouse. so will test it for a few days and hopefully job done.