How to store the result of an executed shell command in a variable in python?

前端 未结 5 1737
执笔经年
执笔经年 2020-12-13 06:20

I need to store the result of a shell command that I executed in a variable, but I couldn\'t get it working. I tried like:

import os    

call = os.system(\"         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 07:21

    In python 3 you can use

    import subprocess as sp
    output = sp.getoutput('whoami --version')
    print (output)
    
    ``
    

提交回复
热议问题