Run batch scripts from AutoIt

comspec-test.au3:

Dim $exitCode = RunWait(@ComSpec & ' /c ' & @ScriptDir & "\find-string.bat hello")

ConsoleWrite($exitCode & @CRLF)

If $exitCode = 1 Then
  MsgBox(0, "", "Not found!")
ElseIf $exitCode = 0 Then
  MsgBox(0, "", "Found!")
EndIf

find-string.bat:

@echo off
setlocal enabledelayedexpansion

echo hello world> hello.txt

set found=N

findstr /C:"%1" hello.txt && set found=Y

echo FOUND !found!

if "!found!"=="Y" (
  exit /b 0
)
if "!found!"=="N" (
  exit /b 1
)
endlocal
goto :eof
Advertisements