All New

user:thomas gists created by user

title:mygist gists with given title

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

Login


All New Login

All gists matching topic command-execution

Recently created
Least recently created
Recently updated
Least recently updated

timmy / 使用 subprocess 執行系統指令

0 likes
0 forks
1 files
Last active 9 months ago
subprocess 模組可用於執行系統指令、與外部程式互動,適用於自動化腳本、批次處理與系統管理等應用。
automation command-execution python shell subprocess
1 import subprocess
2
3 # 執行系統指令並獲取輸出
4 result = subprocess.run(["ls", "-l"], capture_output=True, text=True)
5
6 # 顯示執行結果
7 print("命令輸出:")
8 print(result.stdout)
9
10 # 檢查是否執行成功
Newer Older

Powered by Opengist ⋅ Load: 17ms⋅

English
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文