【求助】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) )
代码如下:
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) )
相关文章推荐
- 怎么用命令行编译运行Java?cmd中javac和java命令的运用?
- 想让命令行(cmd.exe)执行一个命令怎么办
- 怎么用命令行编译运行Java?cmd中javac和java命令的运用?
- Python用subprocess的Popen来调用系统命令
- 命令行cmd下获取路径的命令
- 在cmd命令行里进入和退出Python程序
- Python编写的客户端给服务器发送指令执行相应的命令并返回结果
- python subprocess命令行调用py文件 报错EOFError: EOF when reading a line (已解决)
- Python用subprocess的Popen来调用系统命令
- Python用subprocess的Popen来调用系统命令
- python 怎么和命令行交互
- 打开Word提示向程序发送命令时出现问题怎么办
- CMD命令行下发送邮件,SMTP协议应用,PHP的fsockopen操作
- Python之使用subprocess处理shell命令
- windows下cmd命令行显示UTF8字符设置(CHCP命令)
- 安装好grunt,cmd 提示"grunt不是内部或外部命令" 怎么办?
- 【Python 第20课】命令行常用命令
- 向CMD窗口发送CTRL+C
- WINDOWS下CMD命令行常用命令合集
- python cmd命令