我目前正在编写一个与许多python脚本接口的shell脚本。 在这些Python脚本之一中,我没有明确地启动它,而是调用grass。 当我运行我的shell脚本时,我必须在我称为grass(这是我从官方使用grass页面获得的代码)处点击enter:
startcmd = grass7bin + ' -c ' + file_in2 + ' -e ' + location_path print startcmd p = subprocess.Popen(startcmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) out,err = p.communicate() if p.returncode != 0: print >>sys.stderr,'ERROR: %s' % err print >>sys.stderr,'ERROR: Cannot generate location (%s)' % startcmd sys.exit(-1) else: print 'Created location %s' % location_path gsetup.init(gisbase,gisdb,location,mapset)
我的问题是,我希望这个过程自动运行,而不必每次都按下input! 我已经尝试了许多选项,如pexpect,uinput(由于模块问题而不能很好地工作)。 我知道,在windows中你有msvcrt模块,但我正在与linux …任何想法如何解决这个问题?
httpResponse正在被改变
如何检索shell脚本中使用的所有工具
linux与ARM Tegra 3搭配
将时间跨度转换为shell中的格式化时间
.emacs位置可以用环境variables指定吗?
使用预期功能的pexpect库。
以下是一个与需要用户输入密码的应用程序进行交互的示例:
child = pexpect.spawn('your command') child.expect('Enter password:') child.sendline('your password') child.expect(pexpect.EOF,timeout=None) cmd_show_data = child.before cmd_output = cmd_show_data.split('rn') for data in cmd_output: print data
我终于找到了一个模拟按键的简单快捷的方法:
只需安装xdotool,然后使用下面的代码来模拟例如回车键:
import subprocess subprocess.call(["xdotool","key","Return"])
总结以上是内存溢出为你收集整理的如何运行一个shell脚本而不必按enter / confirm s.th. 其间全部内容,希望文章能够帮你解决如何运行一个shell脚本而不必按enter / confirm s.th. 其间所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)