asgarcymed Posted November 14, 2007 Share Posted November 14, 2007 Today I "discovered": *) AutoIt cannot create "native/pure command-line" scripts; *) AutoIt can run, at least, single command-line executables; for example: Run(@ComSpec & " /c " & "dir /b C:\*.* >list.txt", "", @SW_HIDE) I only want to make one more question about AutoIt and "Command-line"/"Console"/"Terminal"/"Prompt": Can I run commands (via cmd.exe) which has many arguments? Can the external command (interpreted by cmd.exe) be inserted inside a loop statement (as "For...To...Next")? For example - something like this Batch file to automate nrg2iso conversion: CODE@echo off setlocal set fileFilter=*.nrg set workDir=. if not "%~1"=="" set workDir=%~1 if not exist "%workDir%" echo %~1 directory does not exist&goto :EOF pushd "%workDir%" for /f "tokens=*" %%a in ('dir /b /s /a-d "%fileFilter%" 2^>NUL') do call :PROCESS "%%a" popd goto :EOF :PROCESS nrg2iso "%~1" "%~dpn1.iso" goto :EOF The nrg2iso.exe is a command-line tool which converts nrg to iso (CD/DVD image files). nrg2iso.exe has the following syntax: nrg2iso.exe image.nrg image.iso Inside a main folder I have many subfolders (which may have sub-subfolders), and which have different types of files (extensions - *.ext). I need to recursively get all *.nrg files, and then, for each one, call nrg2iso.exe That's what the above batch does. Can this be translated/converted to AutoIt code? Thanks. Regards. MLMK - my blogging craziness... Link to comment Share on other sites More sharing options...
Valuater Posted November 14, 2007 Share Posted November 14, 2007 (edited) Maybe... expandcollapse popup#include <GUIConstants.au3> Dim $_Program = "nrg2iso.exe" Dim $_File = "*.nrg" $GUI = GUICreate("My GUI", 350, 300) $t_label = GUICtrlCreateLabel("Ready", 10, 50, 300, 20) $d_label = GUICtrlCreateLabel("Counter", 10, 100, 300, 20) $Button = GUICtrlCreateButton("GO", 135, 200, 80, 30) GUISetState() While 1 $msg = GUIGetMsg() If $msg = -3 Then Exit If $msg = $Button Then Runner() WEnd Func Runner() Local $numID = 0, $TnumID = 0 GUICtrlSetData($t_label, "Searching for " & $_File & " ...Please wait...") RunWait(@ComSpec & ' /c ' & 'dir "' & @HomeDrive & $_File & '" /a :h /b /s' & ' > "' & @TempDir & '\dir.txt"', '', @SW_HIDE) Sleep(2000) $hFile = FileOpen(@TempDir & "\dir.txt", 0) ; Check if file opened for reading OK If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Return EndIf ; Read in lines of text until the EOF is reached While 1 $sLine = FileReadLine($hFile) If @error = -1 Then ExitLoop If $sLine <> "" Then $numID = $numID + 1 GUICtrlSetData($t_label, "Running - " & $sLine) If $numID >= $TnumID + 5 Then $TnumID = $numID GUICtrlSetData($d_label, " Files Ran: " & $TnumID) EndIf If FileExists($sLine) Then RunWait($_Program & " " & $sLine) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop EndIf WEnd GUICtrlSetData($t_label, "*** Complete ***") FileClose($hFile) EndFunc ;==>Runner 8) Edited November 14, 2007 by Valuater Link to comment Share on other sites More sharing options...
dabus Posted November 14, 2007 Share Posted November 14, 2007 (edited) Since there were many gui/cli questions, you may also be interested to read this topic. Edited November 14, 2007 by dabus Link to comment Share on other sites More sharing options...
asgarcymed Posted November 15, 2007 Author Share Posted November 15, 2007 Valuater - the script you posted is superb!!!!! THANK YOU VERY MUCH!!!!! MLMK - my blogging craziness... Link to comment Share on other sites More sharing options...
Valuater Posted November 15, 2007 Share Posted November 15, 2007 Valuater - the script you posted is superb!!!!!THANK YOU VERY MUCH!!!!! Welcome!!8) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now