[an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] 24x7 Script Archive


Redirecting program output to a file

Dim process_id, number
Dim command, string
Dim output, string
Dim position, number
Dim err_found, boolean

// For this example dynamically create batch file that includes just one command
FileSave( "redir.bat", "ver" )

// Run the batch and terminate it after 30 seconds, in case
// if it does not stop. Batch output is redirected from the
// console to the out.txt file
RunAndWait ("redir.bat >> out.txt", "", 30, process_id)

// Read the output file for error checking
FileReadAll ("out.txt", output)
Lower (output, output)
Pos (output, "error", 1, position)
IsGreater (position, 0, err_found)
If (err_found, NOTIFY, END)

NOTIFY:
// Send email message
MailSend("Exchange Settings", "syspassword", "admin@mycompany.com", "Error occurred while running DOSTEST.BAT")

END:
// Done>