저는 Python을 처음 사용합니다. 나는 유닉스 commmands ("uname -a","uptime","df -h","ifconfig -a","chkconfig --list","netstat -rn","cat /proc/meminfo","ls -l /dev")
의 목록을 가지고 있으며 그들을 실행하고 전체 출력을 .txt
파일로 리디렉션하고 싶습니다. 나는 많은 것을 수색했으나 적절한 해결책을 얻지 못했거나 잘못 이해했다.os.system() 출력을 .txt 파일로 리디렉션하려면
이 for 루프를 사용하여 stdout에서 출력을 가져올 수 있지만 파일로 리디렉션 할 수 없습니다.
def commandsoutput():
command = ("uname -a","uptime","df -h","ifconfig -a","chkconfig --list","netstat -rn","cat /proc/meminfo","ls -l /dev")
for i in command:
print (os.system(i))
commandsoutput()
는'stdout'을 리디렉션 할 수있는'subprocess' 모듈을 살펴 있습니다. –