我在Windows上使用PowerShell和WSL"Ubuntu20.04 LTS".我没有原生Linux发行版,由于嵌套设备的原因,我无法使用虚拟化.
我的目的是在PowerShell中使用Windows Python脚本调用WSL,将一些avd快照解密为原始图像.我已经试过os.popen
、subprocess.Popen
/run
/call
、win32com.client
、multiprocessing
等等.
我可以启动WSL shell,但不会向它传递更多命令.有人知道如何使shell 聚焦,并为更多指示做好准备吗?
代码示例:
from multiprocessing import Process
import win32com.client
import time, os, subprocess
def wsl_shell():
shell = win32com.client.Dispatch("wscript.shell")
shell.SendKeys("Start-Process -FilePath C:\\Programme\\WindowsApps\\CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2021.825.0_x64__79rhkp1fndgsc\\ubuntu2004.exe {ENTER}")
time.sleep(5)
os.popen("ls -l")
if __name__ == '__main__':
ps = Process(target = wsl_shell)
ps.start()