Jump to content

How Do I Do Batch File Commands?


Recommended Posts

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\cookies\*.*

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>

$rc = _RunDos("deltree /y c:\windows\cookies\*.*_

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.

Link to comment
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.

Link to comment
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\cookies\*.*

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>

$rc = _RunDos("deltree /y c:\windows\cookies\*.*_

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 & '"'
Link to comment
Share on other sites

still doesn't work... :)

Run(@ComSpec & "/c" & ' _
deltree /y c:\windows\cookies\*.* _
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)
Link to comment
Share on other sites

still doesn't work... :mellow:

Run(@ComSpec & "/c" & ' _
deltree /y c:\windows\cookies\*.* _
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\cookies\*.*
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
Link to comment
Share on other sites

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\cookies\*.*
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... :mellow:

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.. :o Edited by slightly_abnormal
Link to comment
Share on other sites

I guess I did misunderstand :mellow: 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.. :o

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]
_ArrayAdd($DosCmd, 'deltree /y c:\windows\cookies\*.*')
_ArrayAdd($DosCmd, 'deltree /y c:\windows\tempor~1\*.*')
_ArrayAdd($DosCmd, 'deltree /y c:\progra~1\Netscape\Users\default\Cache\*.jpg')
_ArrayAdd($DosCmd, 'deltree /y c:\progra~1\Netscape\Users\default\Cache\*.gif')
_ArrayAdd($DosCmd, 'deltree /y c:\progra~1\Netscape\Users\default\Cache\*.htm')
_ArrayAdd($DosCmd, 'start "C:\Program Files\Disk Cleaner\dclean.exe"')
_ArrayAdd($DosCmd, 'start "C:\Program Files\CCleaner\ccleaner.exe"')
_ArrayAdd($DosCmd, 'start "C:\Program Files\Webroot\Washer\wwDisp.exe" /shortcut')
_ArrayAdd($DosCmd, 'start "C:\diskcommander.exe" /silence')
_ArrayAdd($DosCmd, 'start "C:\tmpcleanerx.exe"')
$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
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...