【问题标题】:using subprocess for sequence of terminal commands对终端命令序列使用子进程
【发布时间】:2017-10-21 13:25:45
【问题描述】:

我正在尝试制作我的第一个程序,我正在使用 GUI 输入自动执行 git push / clone 进程。

    """GUI GIT Program"""
#Import Statements
from tkinter import *
from tkinter import simpledialog
from tkinter import messagebox
import subprocess
from time import sleep

# set up the GUI
root = Tk()
w = Label(root, text="Git Handler")
w.pack()

# Welcome the User
messagebox.showinfo("Welcome","This is a program to automate your Git stuff!")

# solicit input
user_name = simpledialog.askstring("Username:","What is your username?")
password = simpledialog.askstring("Password","What is your password?",show="*")
message_for_push = simpledialog.askstring("Push Message","What's your push message?")

# do stuff with the data
# call(["git","push"])
# sleep (2)
# call([user_name])
# sleep (2)
# call([password])
commands = '''
git push'''
user_name
password


process = subprocess.Popen('/bin/bash', stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out, err = process.communicate(commands.encode('utf-8'))
print(out.decode('utf-8'))

我遇到的问题是 git push 命令执行了,但下一步输入用户名没有,所有后续命令也是如此......有什么想法吗?

【问题讨论】:

    标签: python terminal subprocess


    【解决方案1】:

    很久以前我遇到过类似的问题,并且能够使用下面的代码 sn-p。

    git-clone () {
        print "Bitbucket checkout enter bitbucket user/pass."
        echo -n "Bitbucket username:"
        read bit_user
        #echo "Bitbucket pass:"
        read -s -p "Bitbucket Password:" bit_pass
        su -c "cd /home/latlongo; git clone https://$bit_user:$bit_pass@bitbucket.org/xyz.git -b your_branch" -m $1
    }
    

    【讨论】:

    • 所以......对不起,我是菜鸟,这只是为了克隆过程吗?还有,bitbucket 是什么?
    • 是的,这是用于克隆的,但您可以将“git clone”命令替换为任何其他 git 命令。您可以将 Bitbucket 视为来自 Atlassian 的商业 git。
    • 遇到一些错误是因为它不喜欢大括号?我应该使用 python 3 添加即时消息
    猜你喜欢
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 2014-03-25
    相关资源
    最近更新 更多