ScriptKeeper Posted September 21, 2009 Share Posted September 21, 2009 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: expandcollapse popup@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:\> Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 21, 2009 Share Posted September 21, 2009 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) 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 More sharing options...
ScriptKeeper Posted September 21, 2009 Author Share Posted September 21, 2009 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) 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 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