writing command line output to file

前端 未结 3 814
粉色の甜心
粉色の甜心 2021-01-12 21:07

I am writing a script to clean up my desktop, moving files based on file type. The first step, it would seem, is to ls -1 /Users/user/Desktop (I\'m on Mac OSX).

3条回答
  •  醉酒成梦
    2021-01-12 21:25

    After skimming the python documentation to run shell command and obtain the output you can use the subprocess module with the check_output method.

    After that you can simple write that output to a file with the standard Python IO functions: File IO in python.

提交回复
热议问题