I have PowerShell installed on ubuntu 20.04 and I want to do the following steps from the python script:
- Invoke it
- Import PowerShell module
- Run Powershell module several times
From the terminal, I would do it as:
pwsh
Import-Module ./MyModule.psd1
MyModule -param 'param_val' -Quiet > filename
several times
I was trying to use
p = subprocess.Popen("pwsh", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
time.sleep(2)
p.stdin.write("Import-Module ./MyModule.psd1")
#in loop
p.stdin.write("MyModule -param 'param_val' -Quiet > filename")
Which is obviously not working. I tried to use Thread
and Queue
but I am afraid that the problem is not in it.
I would be extremely grateful for any help and suggestions.