반응형
나는 이와 같은 것을 시도했지만 효과가 없습니다.
command = "cmd.exe"
proc = subprocess.Popen(command, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
proc.stdin.write("dir c:\\")
해결 방법
아마도 다음과 같은 것을 시도하고 싶을 것입니다.
command = "cmd.exe / C dir C : \\"
cmd.exe
로 파이프 할 수 없다고 생각합니다 ... 유닉스 배경에서 온다면 cmd.exe
에 약간의 엉뚱한 사마귀가 있습니다!
수정 : Sven Marnach에 따르면 cmd.exe
로 파이프를 할 수 있습니다 . 파이썬 셸에서 다음을 시도했습니다.
>>> import subprocess
>>> proc = subprocess.Popen('cmd.exe', stdin = subprocess.PIPE, stdout = subprocess.PIPE)
>>> stdout, stderr = proc.communicate('dir c:\\')
>>> stdout
'Microsoft Windows [Version 6.1.7600]\r\nCopyright (c) 2009 Microsoft Corporatio
n. All rights reserved.\r\n\r\nC:\\Python25>More? '
보시다시피, 아직해야 할 일이 조금 있지만 (첫 번째 줄만 반환 됨)이 작업을 수행 할 수 있습니다.
참조 페이지 https://stackoverflow.com/questions/5486725
반응형
'파이썬' 카테고리의 다른 글
파이썬 Python에서 DateTime 객체의 시간을 자르는 방법은 무엇입니까? (0) | 2020.10.06 |
---|---|
파이썬 Python 시간 측정 기능 (0) | 2020.10.06 |
파이썬 Python에서 반복 건너 뛰기 (0) | 2020.10.06 |
파이썬 matplotlib를 사용하여 축 레이블에 날짜 및 시간이있는 그래프 만들기 (0) | 2020.10.06 |
파이썬 Removing the TK icon on a Tkinter window (0) | 2020.10.06 |
댓글