Sign in to follow this  
Followers 0
ScriptKeeper

Compiled Autoit To Run Abbreviated Commands

3 posts in this topic

I am running a batch script that calls abbreviated compiled autoit scripts however when I go to launch

The abbreviated PowerShell Command the output is all wrong. The "$_" which is used to run PowerShell

should also run the other PowerShell commands not just Write-Host. The first "$_" runs as intended

but when I want to echo a a string to the console I end up with incorrect output. (See Below)

Thank You Very Much For Your Help. I know this is a trivial question but Thank You.

BATCH SCRIPT:

@echo off

:1st Test
REM Parse PowerShell "for" using Cmd "for"
for /f "tokens=*" %%a in ('"$_ for ($i = 0; $i -ile 15; $i += 1) {Write-Host $i}"') do @(

    if %%a lss 5 (
    
        REM Print each value to a seperate line
        !_$plit %%a && (
        
        REM Ping local host for the specified value
        ping localhost -n %%a > nul
        )
        
) else (

    if %%a lss 10 (
    
        REM Print each value to the same line
        !_ %%a && (
        
        REM Ping local host for the specified value
        ping localhost -n %%a > nul
        )

) else (

        REM Use standard "echo" command to echo the remaining values
        echo %%a
        
        )
    )
)

REM Print string all on one line
!_ Finished Running First Test

:2ndTest
REM Use PowerShell.exe to print hello world
$_ Write-Host Hello World

COMPILED AUTOIT SCRIPTS:

$_

Run("PowerShell" & " " & $CmdLineRaw)

!_$plit

$i = 1

While $i <= $CmdLine[0]
    ConsoleWrite($CmdLine[$i] & @CRLF)
    $i = $i + 1
WEnd

!_

ConsoleWrite($CmdLineRaw)

INCORRECT OUTPUT:

C:\>TEST
0
1
2
3
4
5 6 7 8 9 10
11
12
13
14
15
Finished Running First Test
C:\>Hello World

CORRECT OUTPUT: (This is what the output should look like)

C:\>TEST
0
1
2
3
4
5 6 7 8 9 10
11
12
13
14
15
Finished Running First Test
Hello World

C:\>

Share this post


Link to post
Share on other sites



Looks like the batch file exited without waiting for the call to Powershell to return. This happened because the the call to AutoIt finished and returned before the Powershell process did. Change to RunWait() so the AutoIt script doesn't return until the Powershell process completes:

RunWait("PowerShell" & " " & $CmdLineRaw)

:D


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 this post


Link to post
Share on other sites

Looks like the batch file exited without waiting for the call to Powershell to return. This happened because the the call to AutoIt finished and returned before the Powershell process did. Change to RunWait() so the AutoIt script doesn't return until the Powershell process completes:

RunWait("PowerShell" & " " & $CmdLineRaw)

:D

Ok that did not work I changed to RunWait but ended up with this. . .

C:\>TEST
0
1
2
3
4
5 6 7 8 9 10
11
12
13
14
15
Finished Running First TestHello World

C:\>

The app returned to the drive however printed incorrectly :D

Share this post


Link to post
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
Sign in to follow this  
Followers 0