ragupta Posted June 1, 2012 Share Posted June 1, 2012 Hi. Local $foo = Run("powershell.exe", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) <-- Not Working Local $foo = Run("cmd.exe", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) Sleep(2000) StdinWrite($foo, "hostname" & @CRLF & "get-date" & @CRLF ) StdinWrite($foo) Sleep(2000) ; Read from child's STDOUT and show Local $data While True $data &= StdoutRead($foo) If @error Then ExitLoop ConsoleWrite("<>") Sleep(25) WEnd ConsoleWrite( $data & @CRLF) When I use powershell.exe then it just goes into loop though when I use cmd.exe it works fine. Please advice, how to pass input to powershell console. Link to comment Share on other sites More sharing options...
water Posted June 1, 2012 Share Posted June 1, 2012 (edited) I use the following script (snippet) to create an Exchange mailbox for a user and grab STDOUT and STDERR. Hope this helps: $sCMD = "C:\Windows\System32\WindowsPowerShellv1.0powershell.exe -command . " & _ "'D:Exchange ServerV14binRemoteExchange.ps1'; Connect-ExchangeServer -auto; Enable-Mailbox -Identity " & _ $Kurzzeichen & " -Alias " & $Kurzzeichen & " -Database " & $sEXDatabase & $sSMTPAddress $PID = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) StdinWrite($PID, @CRLF) StdinWrite($PID) ; Process STDOUT $sSTDOUT = "" While 1 $sOutput = StdoutRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sSTDOUT = $sSTDOUT & @CRLF & $sOutput WEnd ; Process STDERR $sSTDERR = "" While 1 $sOutput = StdErrRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sSTDERR = $sSTDERR & @CRLF & $sOutput WEnd Edited June 12, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
ragupta Posted June 12, 2012 Author Share Posted June 12, 2012 I use the following script (snippet) toc reate an Exchange mailbox for a user and grab STDOUT and STDERR. Hope this helps: $sCMD = "C:\Windows\System32\WindowsPowerShellv1.0powershell.exe -command . " & _ "'D:Exchange ServerV14binRemoteExchange.ps1'; Connect-ExchangeServer -auto; Enable-Mailbox -Identity " & _ $Kurzzeichen & " -Alias " & $Kurzzeichen & " -Database " & $sEXDatabase & $sSMTPAddress $PID = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) StdinWrite($PID, @CRLF) StdinWrite($PID) ; Process STDOUT $sSTDOUT = "" While 1 $sOutput = StdoutRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sSTDOUT = $sSTDOUT & @CRLF & $sOutput WEnd ; Process STDERR $sSTDERR = "" While 1 $sOutput = StdErrRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sSTDERR = $sSTDERR & @CRLF & $sOutput WEnd I have changed $scmd, i.e. now $sCMD = 'C:\Windows\System32\WindowsPowerShellv1.0powershell.exe -command "get-date"' and rest same same. When I execute this it just exit with success status, without displaying date. Link to comment Share on other sites More sharing options...
water Posted June 12, 2012 Share Posted June 12, 2012 Powershell opens the output window, executes the command and exits. If you want the output window to stay open and display the date you need to add some kind of "wait" command (I'm not familiar with PS at all). My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 12, 2012 Moderators Share Posted June 12, 2012 You could throw in a Start-Sleep Start-Sleep -s 10 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! 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