Jump to content

Executing command in Powershell


Go to solution Solved by sylremo,

Recommended Posts

I want to run windows powershell and  change to a particular directory and then list all the files in that directory using dir command how can I do that. I have tried below command but i don't know how to check the time when all the files have been listed. 

Run("Powershell.exe")
WinWaitActive("Windows PowerShell")
send('cd Z:/test' & "{ENTER}" & "dir" & "{ENTER}")

I want to note the time it take to list files

Edited by Melba23
Posts merged
Link to comment
Share on other sites

  • Solution
Local $hTimer = TimerInit()
Local $sOutput = runPowershell('cd Z:/test; dir')
MsgBox(262144, 'Took ' & TimerDiff($hTimer) & ' ms', $sOutput)

Func runPowershell($sCommand)
    Return runCaptureOutput("powershell -Command " & $sCommand)
EndFunc

Func runCaptureOutput($sCommand)
    Local $iPid = Run(@ComSpec & " /c " & $sCommand, "", @SW_HIDE, 2 + 4)
    Local $sOutput = ""

    While (ProcessExists($iPid))
        Sleep(50)
    WEnd

    Return StdoutRead($iPid)
EndFunc

Hope this helps.

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