반응형
저는 AIX 6.1에서 실행 중이고 Python 2.7을 사용하고 있습니다. 다음 줄을 실행하고 싶지만 오류가 발생합니다.
subprocess.run(["ls", "-l"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'run'
해결 방법
그러나 백 포트하는 것은 쉽습니다.
def run(*popenargs, **kwargs):
input = kwargs.pop("input", None)
check = kwargs.pop("handle", False)
if input is not None:
if 'stdin' in kwargs:
raise ValueError('stdin and input arguments may not both be used.')
kwargs['stdin'] = subprocess.PIPE
process = subprocess.Popen(*popenargs, **kwargs)
try:
stdout, stderr = process.communicate(input)
except:
process.kill()
process.wait()
raise
retcode = process.poll()
if check and retcode:
raise subprocess.CalledProcessError(
retcode, process.args, output=stdout, stderr=stderr)
return retcode, stdout, stderr
타임 아웃에 대한 지원이없고 완료된 프로세스 정보에 대한 사용자 정의 클래스가 없으므로 retcode
, stdout
및 stderr
정보 만 반환합니다. . 그렇지 않으면 원본과 동일한 작업을 수행합니다.
참조 페이지 https://stackoverflow.com/questions/40590192
반응형
'파이썬' 카테고리의 다른 글
파이썬 Openpyxl 인덱스로 워크 시트에서 행을 가져 오는 방법 (0) | 2020.10.26 |
---|---|
파이썬 matplotlib 막대 차트 : 공백 막대 (0) | 2020.10.26 |
파이썬 TypeError : 'int'개체는 구독 할 수 없습니다. (0) | 2020.10.26 |
파이썬 목록으로 Pandas 데이터 프레임 열 선택 (0) | 2020.10.26 |
파이썬 스파이더 누락 된 개체 검사기 (0) | 2020.10.26 |
댓글