如何使用python写批处理

2025-05-14 13:26:06
推荐回答(1个)
回答1:

import subprocess
import sys

ret = subprocess.check_call(['ls', '-l'])
if ret != 0:
    # something wrong! To deal with the exception
    sys.exit(ret)

ret = subprocess.check_call(['rm', '-f', 'file_to_delete'])
if ret != 0:
    # similar to the above

    
#......