mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
win_command win_shell: add stdin option (#31619)
This commit is contained in:
parent
b663f602bc
commit
8e44cd5d10
6 changed files with 85 additions and 4 deletions
|
@ -46,6 +46,7 @@ $chdir = Get-AnsibleParam -obj $params -name "chdir" -type "path"
|
|||
$executable = Get-AnsibleParam -obj $params -name "executable" -type "path"
|
||||
$creates = Get-AnsibleParam -obj $params -name "creates" -type "path"
|
||||
$removes = Get-AnsibleParam -obj $params -name "removes" -type "path"
|
||||
$stdin = Get-AnsibleParam -obj $params -name "stdin" -type "str"
|
||||
|
||||
$raw_command_line = $raw_command_line.Trim()
|
||||
|
||||
|
@ -72,7 +73,11 @@ If(-not $executable -or $executable -eq "powershell") {
|
|||
# Base64 encode the command so we don't have to worry about the various levels of escaping
|
||||
$encoded_command = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($raw_command_line))
|
||||
|
||||
$exec_args = "-noninteractive -encodedcommand $encoded_command"
|
||||
if ($stdin) {
|
||||
$exec_args = "-encodedcommand $encoded_command"
|
||||
} else {
|
||||
$exec_args = "-noninteractive -encodedcommand $encoded_command"
|
||||
}
|
||||
}
|
||||
Else {
|
||||
# FUTURE: support arg translation from executable (or executable_args?) to process arguments for arbitrary interpreter?
|
||||
|
@ -84,9 +89,19 @@ Else {
|
|||
}
|
||||
|
||||
$command = "$exec_application $exec_args"
|
||||
$run_command_arg = @{
|
||||
command = $command
|
||||
}
|
||||
if ($chdir) {
|
||||
$run_command_arg['working_directory'] = $chdir
|
||||
}
|
||||
if ($stdin) {
|
||||
$run_command_arg['stdin'] = $stdin
|
||||
}
|
||||
|
||||
$start_datetime = [DateTime]::UtcNow
|
||||
try {
|
||||
$command_result = Run-Command -command $command -working_directory $chdir
|
||||
$command_result = Run-Command @run_command_arg
|
||||
} catch {
|
||||
$result.changed = $false
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue