Python Script execute commands in Terminal

前端 未结 9 1686
余生分开走
余生分开走 2020-11-29 16:51

I read this somewhere a while ago but cant seem to find it. I am trying to find a command that will execute commands in the terminal and then output the result.

For

9条回答
  •  情深已故
    2020-11-29 17:01

    I prefer usage of subprocess module:

    from subprocess import call
    call(["ls", "-l"])
    

    Reason is that if you want to pass some variable in the script this gives very easy way for example take the following part of the code

    abc = a.c
    call(["vim", abc])
    

提交回复
热议问题