Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to pass a response to a .exe called by PoSh Expand / Collapse
Author
Message
Posted Wednesday, February 13, 2013 9:59 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 5:34 AM
Points: 439, Visits: 1,014
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!



Post #1419634
Posted Wednesday, February 13, 2013 3:33 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:01 PM
Points: 7,139, Visits: 12,762
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
Post #1419759
Posted Thursday, February 14, 2013 7:08 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 5:34 AM
Points: 439, Visits: 1,014
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)




Post #1420044
Posted Thursday, February 14, 2013 7:35 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:01 PM
Points: 7,139, Visits: 12,762
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
Post #1420059
Posted Thursday, February 14, 2013 7:46 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 5:34 AM
Points: 439, Visits: 1,014
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



Post #1420072
Posted Thursday, February 14, 2013 8:05 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:01 PM
Points: 7,139, Visits: 12,762
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
Post #1420095
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse