python中stdin.write

编程入门 行业动态 更新时间:2024-10-10 06:17:02

<a href=https://www.elefans.com/category/jswz/34/1770869.html style=python中stdin.write"/>

python中stdin.write

我注意到两种方法的两种不同的行为应该导致相同的结果。

目标-使用子过程模块执行外部程序,发送一些数据并读取结果。

外部程序是PLINK,平台是WindowsXP,Python版本3.3。

主要思想

execution=["C:\\Pr..\\...\\plink.exe","-l", username,"-pw","***", IP]

a=subprocess.Popen(execution, bufsize=0, stdout=PIPE, stdin=PIPE, stderr=STDOUT, shell=False)

con=a.stdout.readline()

if (con.decode("utf-8").count("FATAL ERROR: Network error: Connection timed out")==0):

a.stdin.write(b"con rout 1

")

print(a.stdout.readline().decode("utf-8"))

a.stdin.write(b"infodf

")

print(a.stdout.readline().decode("utf-8"))

else:

print("ERROR")

a.kill()

到现在为止还挺好。

现在,我希望能够执行一个循环(每次写入子进程的stdin之后),该循环一直等到子进程的stdout的EOF结束后,打印出来,然后再执行另一个

更多推荐

python中stdin.write

本文发布于:2024-02-07 05:56:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:python   stdin   write

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!