Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.sys.mac.programmation > #1485

Re: stdin, stdout non bloquant comment apprendre ?

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:49 +0200
Organization Posted through ALPHANET (http://www.alphanet.ch/)
Message-ID <nl2tfk$sfo$1@shakotay.alphanet.ch> (permalink)
References <nl2g49$s6h$1@shakotay.alphanet.ch> <1mpnmss.15d3m8i1jv0adcN%blanc@empty.org> <nl2sim$ql0$1@shakotay.alphanet.ch>

Show all headers | View raw


Le 30/06/2016 à 12:33, Une Bévue a écrit :
> 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...


Bon ben avec un bête :
stdin.puts gets.chomp if line.chomp.end_with? '?'

script appellant modifié :
--------------------------------------------------------------------------------
#!/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? '?'
         stdin.puts gets.chomp if line.chomp.end_with? '?'
	### MODIFICATION ^^^^############################
         i += 1
       end
     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
--------------------------------------------------------------------------------

mais bon, j'avoue ne pas comprendre "comment ça marche"...

au terminal j'ai maintenant :
.-[yt@mbp.local:~/dev/Ruby/non_blocking]-[16-06-30 12:40:04]
'->$ ./with_pty.rb
Type de recette ? (0)
Entree                    # <<<=== Ce que j'entre au terminal.
Entree (1)
r_type = Entree (2)
.-[yt@mbp.local:~/dev/Ruby/non_blocking]-[16-06-30 12:40:47]
'->$


me reste deux choses :
  - comprendre
  - emballer ça dans un socket

le but :
j'ai un socket sur un serveur auquel j'envoie une action (en fait le nom 
d'un script) avec un paramètre depuis une autre bécanne
le socket lance le script sur le serveur avec le(s) paramètre(s)

et feedback la réponse à une question ***éventuelle*** à la bécanne 
distante.

Back to fr.comp.sys.mac.programmation | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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