Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- Numpy
- ubuntu
- pandas
- error
- Python
- C++
- Selenium
- 컨테이너
- JSON
- label
- SSH
- Visual Studio
- 오류
- Docker
- VS Code
- OpenCV
- YOLO
- Linux
- 프로그래머스
- 기타 연주
- 채보
- nvidia-smi
- windows forms
- pip
- C
- paramiko
- 핑거스타일
- C#
- mysql
- pytorch
Archives
- Today
- Total
기계는 거짓말하지 않는다
Python Shell 명령어, subprocess 본문
간단한 예이다.
Windows에서 실행 한 명령어이며 Linux일 경우 그에 맞는 명령어를 입력한다.
os.system 함수는 가장 간단하게 명령어를 호출할 수 있으나 명령어가 완료될 때까지 대기하며, pid 등을 알 수 없다.
subprocess 함수는 백그라운드로 실행되며 명령어를 호출 한 process의 pid를 얻거나 명령어가 완료될 때까지 기다릴 수 있다.
import os
import subprocess
os.system("timeout /t 5")
process = subprocess.Popen("timeout /t 5", shell=True)
process.wait()
print("shell True End")
process = subprocess.Popen(["timeout", "/t", "5"])
process.wait()
print("no shell args End")
print(process.pid)
'Python' 카테고리의 다른 글
Python 소수점 제한, 출력 (0) | 2022.05.08 |
---|---|
Python Directory 이동, 복사, 삭제(하위 폴더, 디렉터리 포함) (0) | 2022.05.01 |
Python Thread (0) | 2022.04.23 |
Python 객체 유형, 자료형 확인 (0) | 2021.12.06 |
Python XML ElementTree Read (0) | 2021.10.15 |
Comments