# update: 2022-4-25-18 import subprocess def run_command(command, callback=False): """ 执行shell命令 """ if callback: obj = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) lines = obj.stdout.readlines() if len(lines) == 1: lines = str(lines[0], encoding='utf-8').strip('\n') return lines else: return subprocess.Popen(command, shell=True) if __name__ == '__main__': out = run_command('/home/server/resources/vms-files', callback=True) print(out)