live output from subprocess command

后端 未结 16 1176
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 08:16

I\'m using a python script as a driver for a hydrodynamics code. When it comes time to run the simulation, I use subprocess.Popen to run the code, collect the

16条回答
  •  失恋的感觉
    2020-11-22 09:07

    import os
    
    def execute(cmd, callback):
        for line in iter(os.popen(cmd).readline, ''): 
                callback(line[:-1])
    
    execute('ls -a', print)
    

提交回复
热议问题