From: "Ara.T.Howard" Date: 2005-10-11T05:31:52+09:00 Subject: Re: How to use Session 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/be8fe20caacf4e01/13a3edd3544c306c?lnk=st&q=csjasnoch&rnum=4&hl=en#13a3edd3544c306c > > > 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 = Session::new stdout, stderr = sh.execute 'ls' stdout, stderr = 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 run sh = 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 = sh.execute 'foobar' - session can redirect stdout and/or stderr of you use an options hash stdout, stderr = StringIO::new, StringIO::new sh.execute 'foobar', 'stdout' => stdout, 'stderr' => stderr - the exit status of each command is available as status = 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 -- =============================================================================== | 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 ===============================================================================