Followers 0

# How Do I Do Batch File Commands?

## 8 posts in this topic

Hey.. would it be possible to run batch commands in autoit.. I'm talking about a relativley big, but not to big list something like

deltree /y c:\windows\tempor~1\*.*

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm

start "" "C:\Program Files\Disk Cleaner\dclean.exe"

start "" "C:\Program Files\CCleaner\ccleaner.exe"

start "" "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut

start "" "C:\diskcommander.exe" /silence

start "" C:\tmpcleanerx.exe"

this doesn't work , it is supposed to run batch commands.. I have no clue why.. _ are line breaks

#include <Process.au3>

deltree /y c:\windows\tempor~1\*.*_

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg_

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif_

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm" ")

\$rc = _RunDos("start "" "C:\Program Files\Disk Cleaner\dclean.exe" _

start "" "C:\Program Files\CCleaner\ccleaner.exe" _

start "" "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut""_

start "" "C:\diskcommander.exe" /silence_

start "" "C:\tmpcleanerx.exe" ")

I'm stumpped.

##### Share on other sites

Search for ComSpec and take a look at Run and RunWait in the help file (beta?). Place your batch commands in a batch file and call it with Run.

##### Share on other sites

Hey.. would it be possible to run batch commands in autoit.. I'm talking about a relativley big, but not to big list something like

deltree /y c:\windows\tempor~1\*.*

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm

start "" "C:\Program Files\Disk Cleaner\dclean.exe"

start "" "C:\Program Files\CCleaner\ccleaner.exe"

start "" "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut

start "" "C:\diskcommander.exe" /silence

start "" C:\tmpcleanerx.exe"

this doesn't work , it is supposed to run batch commands.. I have no clue why.. _ are line breaks

#include <Process.au3>

deltree /y c:\windows\tempor~1\*.*_

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg_

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif_

deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm" ")

\$rc = _RunDos("start "" "C:\Program Files\Disk Cleaner\dclean.exe" _

start "" "C:\Program Files\CCleaner\ccleaner.exe" _

start "" "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut""_

start "" "C:\diskcommander.exe" /silence_

start "" "C:\tmpcleanerx.exe" ")

I'm stumpped.

To run multiple command line from a single command, you need to either group them within parenthesis or use the ampersand:

```\$Command = '(' & \$Command1 & @CRLF & \$Command2 & ')'
;or
\$Command = '"' & \$Command1 & '&' & \$Command2 & '"'```

##### Share on other sites

still doesn't work...

```Run(@ComSpec & "/c" & ' _
deltree /y c:\windows\tempor~1\*.* _
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg _
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif _
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm _
start "" "C:\Program Files\Disk Cleaner\dclean.exe" _
start "" "C:\Program Files\CCleaner\ccleaner.exe" _
start "" "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut _
start "" "C:\diskcommander.exe" /silence _
start "" C:\tmpcleanerx.exe"',@SW_HIDE)```

##### Share on other sites

still doesn't work...

```Run(@ComSpec & "/c" & ' _
deltree /y c:\windows\tempor~1\*.* _
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg _
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif _
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm _
start "" "C:\Program Files\Disk Cleaner\dclean.exe" _
start "" "C:\Program Files\CCleaner\ccleaner.exe" _
start "" "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut _
start "" "C:\diskcommander.exe" /silence _
start "" C:\tmpcleanerx.exe"',@SW_HIDE)```
You may misunderstand what they were suggesting. Put your CMD shell lines in a batch file. Like CleanUp.cmd:

```REM ===================
REM This is CleanUp.cmd
REM ===================

deltree /y c:\windows\tempor~1\*.*
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm
start "C:\Program Files\Disk Cleaner\dclean.exe"
start "C:\Program Files\CCleaner\ccleaner.exe"
start "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut
start "C:\diskcommander.exe" /silence
start "C:\tmpcleanerx.exe"```

Then just run the batch file, or, if you want to run it from inside an AutoIT script:

`Run(@ComSpec & ' /c CleanUp.cmd', @TempDir, @SW_Show)`

You could also make it more fancy by reading each line of the batch file and running them one at a time, checking for errorlevel after each, reporting errors, etc., but you that would be another thread...

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

#6 ·  Posted (edited)

You may misunderstand what they were suggesting. Put your CMD shell lines in a batch file. Like CleanUp.cmd:

```REM ===================
REM This is CleanUp.cmd
REM ===================

deltree /y c:\windows\tempor~1\*.*
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif
deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm
start "C:\Program Files\Disk Cleaner\dclean.exe"
start "C:\Program Files\CCleaner\ccleaner.exe"
start "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut
start "C:\diskcommander.exe" /silence
start "C:\tmpcleanerx.exe"```

Then just run the batch file, or, if you want to run it from inside an AutoIT script:

`Run(@ComSpec & ' /c CleanUp.cmd', @TempDir, @SW_Show)`

You could also make it more fancy by reading each line of the batch file and running them one at a time, checking for errorlevel after each, reporting errors, etc., but you that would be another thread...

I guess I did misunderstand this is what I did before I used Autoit , I was wondering how I can get batch commands to work in auto it, so I would have only one file, the commands work in batch, but how in can i do the batch commands autoit itself, I know it can be done somehow.. thanks for the suggestions though, dont stop now.. Edited by slightly_abnormal

##### Share on other sites

I guess I did misunderstand this is what I did before I used Autoit , I was wondering how I can get batch commands to work in auto it, so I would have only one file, the commands work in batch, but how in can i do the batch commands autoit itself, I know it can be done somehow.. thanks for the suggestions though, dont stop now..

Here are the same commands run from inside the AutoIT script, with pop-up messages to monitor progress:

```#include <array.au3>

; Create an array of commands to run
Dim \$DosCmd[1]
\$DosCmd[0] = UBound(\$DosCmd) - 1

; Run the commands, reporting results
For \$n = 1 To \$DosCmd[0]
\$RetCode = RunWait(@ComSpec & ' /c ' & \$DosCmd[\$n], @TempDir, @SW_SHOW)
If \$RetCode <> 0 Then
If MsgBox(16 + 1, "Error", "Error occured running command " & \$n & " of " & \$DosCmd[0] & @CRLF & _
@TAB & "Command:  " & \$DosCmd[\$n] & @CRLF & _
@TAB & "ErrorLevel:  " & \$RetCode) = 2 Then Exit
Else
MsgBox(64, "Success", "Successfully completed command " & \$n & " of " & \$DosCmd[0], 5)
EndIf
Next```

This version assumes the test for success is ErrorLevel = 0 on exit, but you can code it to fit your needs.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

thanks for the need demo psaltyds!