이야기박스

Python. Subprocess with * (asterisk) 본문

Programming Language/Python

Python. Subprocess with * (asterisk)

박스님 2020. 11. 17. 18:55
반응형

요약

Subprocess에 *(Asterisk)를 사용하고 싶다면, Shell=True가 필요합니다.

 

If shell is True, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want convenient access to other shell features such as shell pipes, filename wildcards, environment variable expansion, and expansion of ~ to a user’s home directory. However, note that Python itself offers implementations of many shell-like features (in particular, glob, fnmatch, os.walk(), os.path.expandvars(), os.path.expanduser(), and shutil).

 

참조

https://docs.python.org/3/library/subprocess.html#popen-constructor

 

subprocess — Subprocess management — Python 3.9.0 documentation

subprocess — Subprocess management Source code: Lib/subprocess.py The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and

docs.python.org

https://stackoverflow.com/questions/11025784/calling-rm-from-subprocess-using-wildcards-does-not-remove-the-files

 

Calling rm from subprocess using wildcards does not remove the files

I'm trying to build a function that will remove all the files that start with 'prepend' from the root of my project. Here's what I have so far def cleanup(prepend): prepend = str(prepend)

stackoverflow.com

https://stackoverflow.com/questions/24670668/subprocess-call-to-remove-files/24670879

 

subprocess.call() to remove files

I want to remove all the files and directories except for some of them by using `subprocess.call(['rm','-r','!(new_models|creat_model.py|my_mos.tit)'])` but it gives back information rm: cannot

stackoverflow.com

 

반응형