Jump to content

Pass an input to program triggered under cmd prompt


Recommended Posts

I have a shortcut which trigger powershell.exe with some arguments. After launching this shortcut I need to fire some commands on this window and get the output to make sure if the commands are working fine or not.

Let say I have a shorcut icon desctop ... i.e. xyz.lnk

When I doble click it launches console with below content

-----------

C:\Program Files (x86)\xyz>C:\Windows\System32\windowspowershell\v1.0\powershell.exe -NoExit -ExecutionPolicy RemoteSigned -File .\StartxyzPS.ps1

Windows PowerShell

Copyright © 2009 Microsoft Corporation. All rights reserved.

PS C:/>

---------

I can launch using shellexecute but not sure how to pass commands to it

ShellExecute("C:\Users\Public\Desktop\xyz.lnk")

Also when I use Run , cmd prompt closes and script exit before I could use stdinwrite function.

Local $pid = Run(@ComSpec & " /c " & '"C:\Users\Public\Desktop\xyz.lnk"', "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)

Please advise.

Link to comment
Share on other sites

I would too suggest to run the program directly from AutoIt. It's easier to grab the output.

This little code snippet shows how I create an Exchange mailbox for a user and check the output to determine if the mailbox was usccessfully created.

$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 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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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