Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.sys.mac.programmation > #1484
| From | Une Bévue <unbewusst.sein@fai.invalid> |
|---|---|
| Newsgroups | fr.comp.sys.mac.programmation |
| Subject | Re: stdin, stdout non bloquant comment apprendre ? |
| Date | 2016-06-30 12:33 +0200 |
| Organization | Posted through ALPHANET (http://www.alphanet.ch/) |
| Message-ID | <nl2sim$ql0$1@shakotay.alphanet.ch> (permalink) |
| References | <nl2g49$s6h$1@shakotay.alphanet.ch> <1mpnmss.15d3m8i1jv0adcN%blanc@empty.org> |
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