728x90
반응형

파이썬에서 subprocess 를 쓰다보면 종종 발생한다.

subprocess.call([path1, path2]) 형식의 명령어를 쓰다가 에러가 났고

subprocess.call([path1, path2], shell=True) 식으로 처리해서 해결했다.

에러 그림


다른 방법도 있다고 한다.(재부팅이라던지..)

원리는 아래와 같다.

shell = True로 실행 시 일반 shell에서 명령을 내리는 것과 동일하게
별도 유효성 검사 없이 실행이 된다.

그 뜻은 shell = True 설정을 안넣으면, 디폴트로 false로 잡히니까
유효성 검사가되고, 거기서 에러가 날 수 있다는 거같다.

기술문서 상으로는 추천하는 로직이 아니라고 한다(shell injection에 취약)

근데 에러나서 못하는 것보다 실행을 시켜야되지 않을까.(그냥 자동화 도구니..)

 

참조 문서 : https://docs.python.org/2/library/subprocess.html

 

17.1. subprocess — Subprocess management — Python 2.7.18 documentation

17.1. subprocess — Subprocess management 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 functions: os.system os.s

docs.python.org

 

-끝이다-

728x90
반응형

+ Recent posts