r/learnpython • • Jun 05 '21

Running Terminal Commands With Python

I was wondering if there is a way to run terminal commands(ios) with python. Looking to change file names and other tasks that can be done in terminal ie "mv ~/Desktop/MyFile.rtf ~/Desktop/MyFile-old.rtf". Let me know!

1 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/lowerthansound Jun 06 '21

For running the exact example from your post

import subprocess
subprocess.run(
    "mv ~/Desktop/MyFile.rtf ~/Desktop/MyFile-old.rtf",
    shell=True,
)

Not sure how this will deal with stdout and stderr though (read link if you want more information).