print("Command executed successfully") else: print("Command execution failed") 2. 使用subprocess.run() 這是從Python 3.5開(kāi)始推薦的方式,它提供了更多的功能和靈活性。特別是,它允許你捕獲命令的輸出。 1 2 3 4 5 6 importsubprocess try: result=subprocess.run(["ls","-l"], check=True, stdout=su...
www.dbjr.com.cn/python/315289s...htm 2025-6-1