123456789101112131415161718192021222324252627 |
- # update: 2024.9.4
- """
- cd /media/nvidia/nvme0n1/server/repositories/repositories/sri-project.demo-py/3rdparty/xlib
- python3 xsubprocess.py
- """
- 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__':
- command_line = f'find /media/nvidia/nvme0n1/ZJ_PRO_test -type f | wc -l'
- # command_line = 'du -sh /media/nvidia/nvme0n1/test | awk \'{print $1}\''
- out = run_command(command_line, callback=True)
- print(out)
|