I have to invoke two powershell commands via a python script. I am currently using subprocess.Popen for this.
The first command returns a powershell object. Example:
PS>$temp = <powershell_command_1>
The $temp object has multiple properties in it. The entire object has to be passed to a second powershell object in the same script. eg.
PS><powershell_command_2> -object $temp
If $temp were to be a string, I have no problems with passing the python string variable. However, in this case $temp is an object. How can I pass this value to the second PS cmdlet?
Here is the traceback
Traceback (most recent call last):
File "file.py", line 430, in <module>
status = c1.configure_cluster()
File "file.py", line 319, in configure_cluster
configure_cluster = subprocess.Popen([self.powershell_binary,'-ExecutionPolicy','ByPass',r'Cmdlet2', temp], stdout=subprocess.PIPE)
File "C:\Python34\lib\subprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1085, in _execute_child
args = list2cmdline(args)
File "C:\Python34\lib\subprocess.py", line 663, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: Type str doesn't support the buffer API