如何使用python子进程模块执行多个shell命令?

时间:2020-04-13 12:44:30

标签: python subprocess

我在外壳上必须执行多个命令,并且我想在同一外壳上运行所有命令。我将命令存储在文件(// To avoid "java.lang.IllegalArgumentException: navigation destination is unknown to this NavController", se more https://stackoverflow.com/q/51060762/6352712 fun NavController.navigateSafe( @IdRes destinationId: Int, navDirection: NavDirections, callBeforeNavigate: () -> Unit ) { if (currentDestination?.id == destinationId) { callBeforeNavigate() navigate(navDirection) } } fun NavController.navigateSafe(@IdRes destinationId: Int, navDirection: NavDirections) { if (currentDestination?.id == destinationId) { navigate(navDirection) } } )中,我希望使用python中的command.txt函数一次执行所有命令

我尝试过类似的操作,但这不起作用。

subprocess.run()

1 个答案:

答案 0 :(得分:1)

subprocess.run(['sh', 'command.txt'])

请注意,我们不是在这里使用shell=True,因为我们已经自己开始sh

相关问题