Jump to content

trying to use run with powershell and line split


Recommended Posts

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

 

Link to comment
Share on other sites

  • 2 weeks later...

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...