免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3548 | 回复: 5
打印 上一主题 下一主题

問題:等待輸入 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-04-27 22:06 |只看该作者 |倒序浏览
請教各位先進,我想要用 Python 去批量的執行另外一個腳本。

想問問看,在 Python 裡面有沒有功能是可以在,當糸統等待輸入的時候才丟出用串的功能?

例如:
當腳本A等待你輸入Y才往下執行,Python就輸入 Y

论坛徽章:
0
2 [报告]
发表于 2014-04-27 22:10 |只看该作者
用input或raw_input

论坛徽章:
0
3 [报告]
发表于 2014-04-28 09:42 |只看该作者
回复 2# Hadron74


    不好意思,是我表達不明確……

我想用 Python 去執行 另外一個腳本 Perl。在 Perl 裡面要使用者輸入 確認(Y) 。
我的問題是,要如何在 Perl 出現要使用者輸入 確認(Y) 時才讓 Python 輸出 確認(Y) 給 Perl 。

论坛徽章:
0
4 [报告]
发表于 2014-04-30 23:08 |只看该作者
回复 1# play9091

pexpect 行不行?

网上找的
  1. import pexpect  
  2.   
  3. if __name__ == '__main__':  
  4.     user = 'forever'  
  5.     ip = '192.168.0.200'  
  6.     mypassword = 'forever'  
  7.       
  8.     print user  
  9.     child = pexpect.spawn('ssh %s@%s' % (user,ip))  
  10.     child.expect ('password:')  
  11.     child.sendline (mypassword)  
  12.       
  13.     child.expect(')  
  14.     child.sendline('sudo -s')  
  15.     child.expect (':')  
  16.     child.sendline (mypassword)  
  17.     child.expect('#')  
  18.     child.sendline('ls -la')  
  19.     child.expect('#')  
  20.     print child.before   # Print the result of the ls command.  
  21.     child.sendline("echo '112' >> /home/forever/1.txt ")  
  22.     child.interact()     # Give control of the child to the user.  
复制代码

论坛徽章:
0
5 [报告]
发表于 2014-05-01 12:10 |只看该作者
subprocess 里的 call里边有个 comunicate可以。

论坛徽章:
0
6 [报告]
发表于 2014-05-20 13:27 |只看该作者
謝謝大家,我通過修改源碼內的變數解決了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP