我想从我的python脚本调用多个命令。
我尝试使用os.system(),但是在更改当前目录时遇到了问题。
例子:
os.system("ls -l")
os.system("<some command>") # This will change the present working directory
os.system("launchMyApp") # Some application invocation I need to do.
现在,第三个调用启动无效。
最佳答案
os.system
是标准C函数 system()
的包装,因此其参数可以是任何有效的shell command,只要它适合为进程的环境和参数列表保留的内存即可。
因此,用分号或换行符分隔这些命令,它们将在同一环境中顺序执行。
os.system(" ls -l; <some command>; launchMyApp")
os.system('''
ls -l
<some command>
launchMyApp
''')
关于python - 在Python中使用os.system调用多个命令,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20042205/