繁体   English   中英

有什么方法可以打开 git-bash 并在 Python 中发送命令?

[英]Is there any way to open git-bash and send commands in Python?

from tkinter import *
import os


pencere = Tk()
pencere.title("Hello")
pencere.geometry("550x550")
label1 = Label(text="Hallo",font="bold 25")
label1.place(x=150,y=30)

label2 = Label(text="Command")
label2.place(x=5,y=90)

label3 = Entry(width=50)
label3.place(x=50,y=90)

def gitbash():
    os.startfile('C:\\Program Files\\Git\\git-bash.exe')

ac = Button(text="Olustur",width=10,height=3,command = cmd)
ac.place(x=100,y=150)


pencere = mainloop()

我想从 gitbash function 向 GitBash 发送命令。 例如我想发送“ls”命令,当我打开 Button 时,应该打开 GitBash 并发送 ls 命令。

为此,您可以使用一个名为subprocess的模块

import subprocess

subprocess.run("ipconfig", shell=True, capture_output=True)

这段代码将运行ipconfig并将在 shell 中运行,并且还将捕获 output

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM