From: Victor Reyes Date: 2005-10-12T00:05:40+09:00 Subject: Re: How to use Session ------=_Part_6830_30946706.1129043136489 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Session appears to be a nice tool for sys admins. I noticed by following the first link listed that session-2.4.0/app= ears to be the latest. Is this true? Also, is session distributed with any of the Ruby version? if not, will it be distributed with Ruby any time soon? Thank you On 10/10/05, Ara.T.Howard wrote: > > On Tue, 11 Oct 2005, csjasnoch@wisc.edu wrote: > > > I do not understand how Session works. > > > > I had requested info before for thread scheduling and was pointed to > > it... > > > http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/be8fe2= 0caacf4e01/13a3edd3544c306c?lnk=3Dst&q=3Dcsjasnoch&rnum=3D4&hl=3Den#13a3edd= 3544c306c > > > > > > But there is no help it seems on the workings of it so I am baffled. Is > > there a clear description on its usage somewhere? > > starting at the top directory > > http://codeforpeople.com/lib/ruby/session/ > > and looking at the latest version > > http://codeforpeople.com/lib/ruby/session/session-2.4.0/ > > there are quite a few examples > > http://codeforpeople.com/lib/ruby/session/session-2.4.0/sample/ > > and, of course, the tests > > http://codeforpeople.com/lib/ruby/session/session-2.4.0/test/session.rb > > the README > > http://codeforpeople.com/lib/ruby/session/session-2.4.0/README > > which gives the, most simple, of examples > > require 'session' > > sh =3D Session::new > > stdout, stderr =3D sh.execute 'ls' > stdout, stderr =3D sh.execute 'echo 42' > > what, exactly, are you trying to do? > > perhaps this helps: > > - sessions are persistent, you only need ONE for all commands you will ru= n > > sh =3D Session::new > > sh.execute 'ls' > sh.execute 'date' > sh.execute 'echo 42' > > - sessions return both the stdout and stderr of all commands run > > stdout, stderr =3D sh.execute 'foobar' > > - session can redirect stdout and/or stderr of you use an options hash > > stdout, stderr =3D StringIO::new, StringIO::new > > sh.execute 'foobar', 'stdout' =3D> stdout, 'stderr' =3D> stderr > > - the exit status of each command is available as > > status =3D sh.exit_status # or sh.status or sh.exitstatus > > - a block can be given to execute to handle stdout and stderr as it > arrives, > the block is passed both the stdout buffer and the stderr buffer, one of > them may be nil (empty) > > sh.execute('long_running_command') do |stdout, stderr| > if stdout > log.info{ "stdout: #{ stdout }" } > end > if stderr > log.info{ "stderr: #{ stderr }" } > end > end > > - sessions are thread safe in that executing a command from one thread > will > not block all other threads > > hth. > > -a > -- > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > | email :: ara [dot] t [dot] howard [at] noaa [dot] gov > | phone :: 303.497.6469 > | Your life dwells amoung the causes of death > | Like a lamp standing in a strong breeze. --Nagarjuna > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > > ------=_Part_6830_30946706.1129043136489--