您的位置:首页 > 编程语言 > Python开发

【求助】python中subprocess向cmd发送命令行,怎么发送ctrl+c的命令?

2017-12-31 19:14 936 查看
python3写了一个subprocess向cmd发送命令行的程序,现在想在发送返回过程中停止,就像是cmd发送ctrl+c,查了一些资料,说是发送0x03但是没有反应啊

代码如下:

sub = subprocess.Popen(cmd, shell = True ,bufsize = -1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, \

                               stderr=subprocess.STDOUT)

        

        while True :      

            if flag:

                print('flag:'+str(flag))

                sub.stdin.write(byte(0x03)) 

            datetime_dt = datetime.datetime.today()  # 获取当前日期和时间

            datetime_str = datetime_dt.strftime("%Y/%m/%d %H:%M:%S.%f")  # 格式化日期时间

            resText = sub.stdout.readline().decode('gbk')

            if resText == '': 

                break  

            textLog.insert(tk.END,datetime_str+ ' -| INFO - | ' +str(resText) ) 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: