如何在命令提示符下自动输入用户? [英] How to automate user input at the command prompt?

查看:121
本文介绍了如何在命令提示符下自动输入用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在研究在Windows机器上使用的scirpt,我需要在命令提示符下自动输入用户输入的
。例如,我正在使用

os.system(''mycommand'')来执行我想要的命令。然而,这些命令中的一些将提示用户确认是或否。

python中是否有任何内容可以让我的脚本自动化这些

输入

另一个例子是,如果我输入format c:\,在命令

提示它会警告我并要求我键入''y'继续。我可以使用os.system来自动化格式c:\但有没有办法让
自动化''y''输入部分。我尝试在Interent上搜索帮助

,但似乎无法找到有关如何使用Python执行此操作的任何信息。可以有人

给我一些确认,如果我想做的话是否可行。

提前感谢您的帮助。


I''m working on a scirpt to be used on a windows machine and I need to
automate a user''s input on the command prompt. For example I''m using
os.system(''mycommand'') to excute the commands I want. However some of
these command will prompt for a confirmation of yes or no from user.
Is there anything in python that will allow my script to automate these
input
Another example is let say if i type "format c:\" on the command
prompt it will warn me and ask me to type ''y'' to continue. I can use
the os.system to automate the "format c:\" but is there a way to
automate the ''y'' input part. I try searching for help on the Interent
but cant seem find any info on how to do this with Python. Can someone
give me some confirmation if what I want to do is possible or not.
Thanks in advance for any help.

推荐答案

嗨!


同样的问题。我用popenX和子进程进行了长时间的搜索。实际上,我没有实际上有任何解决方案......


建议:第一个发现阻止其他人...


@ +


Michel Claveau

Hi!

Same problem. I had search, long time, with popenX, with subprocess. I don''t
have, actually, any solution...

Suggestion: the first which finds prevents the others...

@+

Michel Claveau




你可能想看看pexpect:

http:// pexpect。 sourceforge.net/


但我不确定它对Windows的支持。

ge ***** @ yahoo.com 写道:

You may want to look at pexpect:

http://pexpect.sourceforge.net/

But I am not sure about its support on windows.

ge*****@yahoo.com wrote:

我正在努力做一个scirpt在Windows机器上使用我需要

在命令提示符下自动输入用户的输入。例如,我正在使用

os.system(''mycommand'')来执行我想要的命令。然而,这些命令中的一些将提示用户确认是或否。

python中是否有任何内容可以让我的脚本自动化这些

输入

另一个例子是,如果我输入format c:\,在命令

提示它会警告我并要求我键入''y'继续。我可以使用os.system来自动化格式c:\但有没有办法让
自动化''y''输入部分。我尝试在Interent上搜索帮助

,但似乎无法找到有关如何使用Python执行此操作的任何信息。可以有人

给我一些确认,如果我想做的话是否可行。

提前感谢您的帮助。
I''m working on a scirpt to be used on a windows machine and I need to
automate a user''s input on the command prompt. For example I''m using
os.system(''mycommand'') to excute the commands I want. However some of
these command will prompt for a confirmation of yes or no from user.
Is there anything in python that will allow my script to automate these
input
Another example is let say if i type "format c:\" on the command
prompt it will warn me and ask me to type ''y'' to continue. I can use
the os.system to automate the "format c:\" but is there a way to
automate the ''y'' input part. I try searching for help on the Interent
but cant seem find any info on how to do this with Python. Can someone
give me some confirmation if what I want to do is possible or not.
Thanks in advance for any help.



dr ***** **@gmail.com 写道:

你可能想看看pexpect:

http://pexpect.sourceforge.net/


但我是不确定它在Windows上的支持。
You may want to look at pexpect:

http://pexpect.sourceforge.net/

But I am not sure about its support on windows.



就我最近的调查而言,以及与pexpect的

作者的电子邮件交换,Windows不支持。

To the best of my recent investigation, and an email exchange with the
author of pexpect, it is NOT supported under Windows.


这篇关于如何在命令提示符下自动输入用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆