Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.sys.mac.programmation > #1484
| Path | csiph.com!1.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!news.roellig-ltd.de!open-news-network.org!news.alphanet.ch!alphanet.ch!.POSTED!not-for-mail |
|---|---|
| From | Une Bévue <unbewusst.sein@fai.invalid> |
| Newsgroups | fr.comp.sys.mac.programmation |
| Subject | Re: stdin, stdout non bloquant comment apprendre ? |
| Date | Thu, 30 Jun 2016 12:33:58 +0200 |
| Organization | Posted through ALPHANET (http://www.alphanet.ch/) |
| Lines | 65 |
| Sender | unbewusstsein@vbo91-4-88-164-253-93.fbx.proxad.net |
| Message-ID | <nl2sim$ql0$1@shakotay.alphanet.ch> (permalink) |
| References | <nl2g49$s6h$1@shakotay.alphanet.ch> <1mpnmss.15d3m8i1jv0adcN%blanc@empty.org> |
| NNTP-Posting-Host | vbo91-4-88-164-253-93.fbx.proxad.net |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | shakotay.alphanet.ch 1467282838 27296 88.164.253.93 (30 Jun 2016 10:33:58 GMT) |
| X-Complaints-To | usenet@alphanet.ch |
| NNTP-Posting-Date | Thu, 30 Jun 2016 10:33:58 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 |
| In-Reply-To | <1mpnmss.15d3m8i1jv0adcN%blanc@empty.org> |
| Xref | csiph.com fr.comp.sys.mac.programmation:1484 |
Show key headers only | View raw
Le 30/06/2016 à 11:36, JiPaul a écrit :
> Que veux-tu dire par "simuler" ? N'est-ce pas une vrai entrée que tu
> souhaites faire ?
Si si, mais je la simule, pour l'instant.
bon en utilisant PTY, ça roule nettement mieux :
script appellant :
--------------------------------------------------------------------------------
#!/usr/bin/env ruby
# encoding: utf-8
# ~/dev/Ruby/non_blocking/with_pty.rb
$: << "#{ENV['HOME']}/bin/ruby_lib"
=begin
Continuously read from STDOUT of external process in Ruby
http://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby
=end
require 'rubygems'
require 'pty'
cmd =
"/Users/yt/dev/Ruby/non_blocking/popen3_simple_implementation_in_test_child.rb"
begin
PTY.spawn( cmd ) do |stdout, stdin, pid|
begin
# Do stuff with the output here. Just printing to show it works
i = 0
stdout.each do |line|
puts line.chomp + " (#{i})"
stdin.puts "Entree" if line.chomp.end_with? '?'
i += 1
end
#stdin.puts
rescue Errno::EIO
puts "Errno:EIO error, but this probably just means " +
"that the process has finished giving output"
end
end
rescue PTY::ChildExited
puts "The child process exited!"
end
--------------------------------------------------------------------------------
même script appelé que précédemment.
donc c'est déjà nettement mieux car je peux détecter le "?" de la
question et y répondre.
reste à remplacer la ligne :
stdin.puts "Entree" if line.chomp.end_with? '?'
par quelque chose du genre :
stdin.puts gets.chomp if line.chomp.end_with? '?'
avec le "gets.chomp" opérant sur le stdin du terminal...
le résultat actuel :
.-[yt@mbp.local:~/dev/Ruby/non_blocking]-[16-06-30 12:24:47]
'->$ ./with_pty.rb
Type de recette ? (0)
Entree (1)
r_type = Entree (2)
.-[yt@mbp.local:~/dev/Ruby/non_blocking]-[16-06-30 12:26:29]
'->$
Back to fr.comp.sys.mac.programmation | Previous | Next — Previous in thread | Next in thread | Find similar
stdin, stdout non bloquant comment apprendre ? Une Bévue <unbewusst.sein@fai.invalid> - 2016-06-30 09:01 +0200
Re: stdin, stdout non bloquant comment apprendre ? blanc@empty.org (JiPaul) - 2016-06-30 11:36 +0200
Re: stdin, stdout non bloquant comment apprendre ? Une Bévue <unbewusst.sein@fai.invalid> - 2016-06-30 11:48 +0200
Re: stdin, stdout non bloquant comment apprendre ? Une Bévue <unbewusst.sein@fai.invalid> - 2016-06-30 12:33 +0200
Re: stdin, stdout non bloquant comment apprendre ? Une Bévue <unbewusst.sein@fai.invalid> - 2016-06-30 12:49 +0200
Progrès : stdin, stdout non bloquant comment apprendre ? Une Bévue <unbewusst.sein@fai.invalid> - 2016-06-30 14:04 +0200
Re: Progrès : stdin, stdout non bloquant comment apprendre ? Une Bévue <unbewusst.sein@fai.invalid> - 2016-06-30 14:07 +0200
csiph-web