[ANN] session-2.1.8

URLS: |

   http://raa.ruby-lang.org/project/session/
   http://www.codeforpeople.com/lib/ruby/session/

NAME: |

   Session
     ::Sh
     ::Bash
     ::Shell
     ::IDL

SYNOPSIS: |

   Session::* offers a set of class for driving external progams via pipes. It
   offers a significant abstraction over Open3::popen since stdout/stderr can
   be processed individually for each command. Additionally the exit_status of
   each command is made available. eg.

     bash = Session::Bash.new
     stdout, stderr = bash.execute 'ls'

   or

     bash = Session::Bash.new
     stdout, stderr = StringIO.new, StringIO.new

     bash.execute 'ls', :stdout => stdout, :stderr => stderr
     exit_status = bash.exit_status

   or

     bash = Session::Bash.new

···

#
   # output is passed to the block as it is produced
   #
     bash.execute( 'long_running_command.exe' ) do |out, err|
       logger << out if out
       elogger << err if err
     end

   Sessions are Thread safe (in the sense that they do not block on io
   operations) allowing command spawn from guis to update widgets with output
   while running in the background.

     button.configure 'action' => lambda do
       sh = Session::new
       sh.execute(cmd) do |o,e|
         out_widget.update o if o
         err_widget.update e if e
       end
     end

SAMPLES: |

   see samples/*

AUTHOR: |

   ara.t.howard@noaa.gov

HISTORY: |

   2.1.8:
     - greatly simplified read loop using two reader threads, one for stderr and
       one for stdout alongside a mutex to protect data. this streamlined the code
       alot vs. the old select method including allowing removal of the linbuffer
       class. the interface remains exactly as before however.
   2.1.7:
     - improved thread safe non-blocking read method
     - gemspec
   2.1.6:
     - wrapped send_command in a Thread (send async) so output processing can
       commend immeadiately. this was o.k. before, but had strange behaviour when
       using popen3 from threads. thanks to tanaka akira for this suggestion.
     - iff ENV['SESSION_USE_SPAWN'] is set Session uses Spawn::spawn instead of
       Open3::popen3. also noted that spawn seems to be a bit faster.
     - added tests for threads.
     - run 'sh SESSION_USE_SPAWN=1 ruby test/session.rb' to test using spawn
     - added test for idl so it's test is not run if system doesn't have it, all
       that should be required for 'ruby test/session.rb' is should be sh'
     - removed sample/tcsh and note about Tcsh and Csh in README - stderr
       redirection/separation is flaky in those shells
   2.1.5:
     - added Session.use_spawn=, AbstractSession.use_spawn=, and an :use_session=>
       option to AbstractSession#initialize. if any of them are set the code uses
       Spawn::spawn to create external processes instead of Open3::popen3.
       Spawn::spawn uses named pipes (fifos) for IPC instead of forking and pipes.
       the fork used in popen3 can cause strange behaviour with multi-threaded apps
       (like a tk app). see source for details
   2.1.4:
     - added Thread.exclusive{} wrapper when io is read to works in multi
       threaded apps

enjoy.

-a
--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen

===============================================================================

This looks like it works really well, thanks :slight_smile:

A small bug: Setting .track_history after creation (it has a write
accessor) causes #execute() to fail as @history is only assigned in
the constructor.

Leon

···

On Wed, 6 Oct 2004 01:44:52 +0900, Ara.T.Howard <ara.t.howard@noaa.gov> wrote:

   Session::* offers a set of class for driving external progams via pipes. It
   offers a significant abstraction over Open3::popen since stdout/stderr can
   be processed individually for each command. Additionally the exit_status of
   each command is made available. eg.

HISTORY:

   2.1.9:
     - fixed bug where setting track history after creation caused later failure in
       execute (@history = only in ctor). thanks leon breedt
       <bitserf@gmail.com>!
     - updates to README
     - included session-x.x.x.rpa file - thanks batsman <batsman.geo@yahoo.com>
     - to_str/to_s/to_yaml for History/Command is now valid yaml (updated samples
       to reflect this)
     - inspect for History/Command is now ruby's default

   2.1.8:
     - greatly simplified read loop using two reader threads, one for stderr and
       one for stdout alongside a mutex to protect data. this streamlined the code
       alot vs. the old select method including allowing removal of the linbuffer
       class. the interface remains exactly as before however.

   2.1.7:
     - improved thread safe non-blocking read method
     - gemspec

   2.1.6:
     - wrapped send_command in a Thread (send async) so output processing can
       commend immeadiately. this was o.k. before, but had strange behaviour when
       using popen3 from threads. thanks to tanaka akira for this suggestion.
     - iff ENV['SESSION_USE_SPAWN'] is set Session uses Spawn::spawn instead of
       Open3::popen3. also noted that spawn seems to be a bit faster.
     - added tests for threads.
     - run 'sh SESSION_USE_SPAWN=1 ruby test/session.rb' to test using spawn
     - added test for idl so it's test is not run if system doesn't have it, all
       that should be required for 'ruby test/session.rb' is should be sh'
     - removed sample/tcsh and note about Tcsh and Csh in README - stderr
       redirection/separation is flaky in those shells

   2.1.5:
     - added Session.use_spawn=, AbstractSession.use_spawn=, and an :use_session=>
       option to AbstractSession#initialize. if any of them are set the code uses
       Spawn::spawn to create external processes instead of Open3::popen3.
       Spawn::spawn uses named pipes (fifos) for IPC instead of forking and pipes.
       the fork used in popen3 can cause strange behaviour with multi-threaded apps
       (like a tk app). see source for details

   2.1.4:
     - added Thread.exclusive{} wrapper when io is read to works in multi
       threaded apps

URLS: |

   http://raa.ruby-lang.org/project/session/
   http://www.codeforpeople.com/lib/ruby/session/

NAME: |

   Session
     ::Sh
     ::Bash
     ::Shell
     ::IDL

SYNOPSIS: |

   Session::* offers a set of classes built upon Open3::popen3 for driving
   external progams via pipes. It offers a significant abstraction over
   Open3::popen in that the stdout/stderr of each command sent can be deliniated:

     open3:

         i.o,e = Open3::popen3 '/bin/sh'

         i.puts 'ls'
         i.puts 'echo 42'

     now, how to determine the boundry between the output from 'ls' and 'echo'?
     the only (simple) way is start a process for each command

         i.o,e = Open3::popen3 '/bin/sh'
         i.puts 'ls'
         i.close
         stdout, stderr = o.read, e.read

         i.o,e = Open3::popen3 '/bin/sh'
         i.puts 'echo 42'
         i.close
         stdout, stderr = o.read, e.read

     session:

       sh = Session::new

       stdout, stderr = sh.execute 'ls'
       stdout, stderr = sh.execute 'echo 42'

   Both stderr and stdout can be redirected, and the exit_status of each command
   is made available:

       bash = Session::Bash.new
       stdout, stderr = StringIO::new, StringIO::new

       bash.execute 'ls', :stdout => stdout, :stderr => stderr
       # bash.execute 'ls', 1 => stdout, 2 => stderr # same thing
       # bash.execute 'ls', :o => stdout, :e => stderr # same thing

       exit_status = bash.exit_status

   A block form can be used to specify a callback to be invoked whenever output
   has become availible:

     bash = Session::Bash.new

     bash.execute( 'long_running_command.exe' ) do |out, err|
       logger << out if out
       elogger << err if err
     end

   Sessions are Thread safe (in the sense that they do not block on io
   operations) allowing commands spawned from guis to update widgets with output
   while running in the background.

     button.configure 'action' => lambda do
       sh = Session::new
       sh.execute(cmd) do |o,e|
         out_widget.update o if o
         err_widget.update e if e
       end
     end

SAMPLES: |

   see samples/*

AUTHOR: |

   ara.t.howard@noaa.gov
-a

···

--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen

===============================================================================

batsman@tux-chan:~/src/rpa/ports$ rpa update
Getting port info from http://rpa-base.rubyforge.org/ports/ports.info\.
100% [========================================] 84281 bytes

Ports updated since the last 'rpa update'
session 2.1.8-2 -> 2.1.9-1

batsman@tux-chan:~/src/rpa/ports/session-2.1.8$ rpa install session
Installing ports
Getting port session from http://rpa-base.rubyforge.org/ports/session_2.1.9-1.rps\.
100% [========================================] 12288 bytes
Building session (2.1.9-1).
Generating RI data files.
Generating RDoc HTML documentation.
Calculating MD5 digests.
Building package in session_2.1.9-1_i686-pc-linux-gnu.rpa.
  Installing session
Reusing cached package /home/batsman/usr/lib/ruby/rpa0.0/packages/session_2.1.9-1_i686-pc-linux-gnu.rpa.
Starting lightweight (metadata only) transaction for session
Checking for file conflicts in session.
Starting transaction for session
Preparing to replace session 2.1.8-2 with /home/batsman/usr/lib/ruby/rpa0.0/packages/session_2.1.9-1_i686-pc-linux-gnu.rpa
Package /home/batsman/usr/lib/ruby/rpa0.0/packages/session_2.1.9-1_i686-pc-linux-gnu.rpa unpacked.
Finished transaction for session
Starting lightweight (metadata only) transaction for session
Finished lightweight (metadata only) transaction for session
Finished lightweight (metadata only) transaction for session
Committed changes

···

On Thu, Oct 07, 2004 at 12:24:49AM +0900, Ara.T.Howard@noaa.gov wrote:

HISTORY:

  2.1.9:
    - fixed bug where setting track history after creation caused later
    failure in
      execute (@history = only in ctor). thanks leon breedt
      <bitserf@gmail.com>!
    - updates to README
    - included session-x.x.x.rpa file - thanks batsman
    <batsman.geo@yahoo.com>
    - to_str/to_s/to_yaml for History/Command is now valid yaml (updated
    samples
      to reflect this)
    - inspect for History/Command is now ruby's default

--
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com