Jump to content
dwaynek

trying to use run with powershell and line split

Recommended Posts

Posted (edited)

trying to use this powershell command with Run but nothing comes out in $sOutput.

the powershell portion works on the command line but not when its used in an autoit script:

Local $iPID=Run('powershell "((gwmi win32_process | select CommandLine| Select-String -Pattern firefox.exe,GoogleChromePortable -CaseSensitive).line).split('-')|Select-String -Pattern CommandLine|Sort-Object|Get-Unique"', "d:\my documents\bat",@SW_SHOW,$STDOUT_CHILD + $STDERR_CHILD)

; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)

Local $sOutput = StdoutRead($iPID)
msgbox(0,"",$sOutput)

 

it has something to do with the split ('-') i think bcz if i remove everything from the line split portion onwards, it works fine.

Edited by dwaynek

Share this post


Link to post
Share on other sites

Because the "program" parameter of the "Run" function is entirely incased within single quotes, ('...'), any single quotes, ('), within the "program" parameter must be doubled, (''), to be recognized as single quotes, ('..''...''..').

#include <AutoItConstants.au3>

Local $iPID = Run('powershell "((gwmi win32_process | select CommandLine| Select-String -Pattern firefox.exe,GoogleChromePortable -CaseSensitive).line).split(''-'')|Select-String -Pattern CommandLine|Sort-Object|Get-Unique"', "", @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)

; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)

Local $sOutput = StdoutRead($iPID)
MsgBox(0, "", $sOutput)

 

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

×
×
  • Create New...