How to pass a response to a .exe called by PoSh

  • I'm calling an command line .exe from within a PoSh script.

    This is generating a hit Y for Yes / N for No choice.

    How can I send a Y in my PoSh script?

    Thanks!

  • I think that is up to the program being called not PowerShell. If the program wants to accept input interactively and does not provide an input parameter for the information or a way to provide an "answer file" then I am not sure you can get around that.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Hmmmmm.

    I found this on the net; the author plainly states it's a bit of a hack, but also claims to have made it work for him. I've not been able to get this to work myself.

    #Pass the Y and exit

    $PlinkCommand = [string]::Format('echo y | & "{0}" {1} exit',

    $PlinkAndPath, $plinkoptions )

    Write-Host $PlinkCommand

    $msg = Invoke-Expression $PlinkCommand

    Where

    $PlinkAndPath is path to .exe, and

    $plinkoptions are the parameters (username, password, hostname, etc)

  • That's not a PowerShell thing per se. What that is saying is:

    echo textToPipeIn | executableName executableOptions

    Which works fine in cmd Shell as well. How to pipe in more than one answer with that syntax though?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Yeah, I know it's a cmd hack, and you're right, it'll only work for a single response.

    In my particular case, that's all that would have been required.

    I got around it per your suggestion by using another switch.

    Thanks!

    P

  • Good deal. Thanks for posting back that it was sorted.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply