Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

python - Invoke-Command with subprocess.popen doesn't work

I have a PowerShell script, in which I have the commands:

$Username = 'user'
$Password = 'pass'
$SecureString = ConvertTo-SecureString -AsPlainText $Password -Force
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $SecureString

$name= $args[0]
$cmd= $args[1]

$s= New-PSSession -VMName $name-Credential $MySecureCreds
Invoke-Command -Session $s -Command {$cmd}
Remove-PSSession -Session $s

And I want to run it from python with open using these commands:

sp = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
(out, err) = sp.communicate()

My PowerShell command that I created in python is this

powershell_cmd = Start-Process -NoNewWindow -FilePath path_to_installer.exe -ArgumentList /S, --accept_license_agreement, --license_validation_file=path_to_license.bat

but when I try to run it, nothing happens on the virtual machine.

Can you help me with a hint, or what other technology can I use with python to run this command on the virtual machine?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...