[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] systemu-1.2.0

ara.t.howard

12/6/2007 11:02:00 PM

NAME

systemu

SYNOPSIS

univeral capture of stdout and stderr and handling of child
process pid for windows, *nix, etc.

URIS

http://rubyforge.org/projects/code...
http://codeforpeople.com...
http://codeforpeople.rubyforg...

INSTALL

gem install systemu

HISTORY

1.2.0

- fixed handling of background thread management - needed
Thread.current.abort_on_exception = true

- fixed reporting of child pid, it was reported as the parent's
pid before

SAMPLES

<========< samples/a.rb >========>

~ > cat samples/a.rb

#
# systemu can be used on any platform to return status, stdout,
and stderr of
# any command. unlike other methods like open3/popen4 there is
zero danger of
# full pipes or threading issues hanging your process or
subprocess.
#
require 'systemu'

date = %q( ruby -e" t = Time.now; STDOUT.puts t; STDERR.puts
t " )

status, stdout, stderr = systemu date
p [ status, stdout, stderr ]

~ > ruby samples/a.rb

[#<Process::Status: pid=987,exited(0)>, "Thu Dec 06 16:01:59
-0700 2007\n", "Thu Dec 06 16:01:59 -0700 2007\n"]


<========< samples/b.rb >========>

~ > cat samples/b.rb

#
# quite a few keys can be passed to the command to alter it's
behaviour. if
# either stdout or stderr is supplied those objects should
respond_to? '<<'
# and only status will be returned
#
require 'systemu'

date = %q( ruby -e" t = Time.now; STDOUT.puts t; STDERR.puts
t " )

stdout, stderr = '', ''
status = systemu date, 'stdout' => stdout, 'stderr' => stderr
p [ status, stdout, stderr ]

~ > ruby samples/b.rb

[#<Process::Status: pid=992,exited(0)>, "Thu Dec 06 16:01:59
-0700 2007\n", "Thu Dec 06 16:01:59 -0700 2007\n"]


<========< samples/c.rb >========>

~ > cat samples/c.rb

#
# of course stdin can be supplied too. synonyms for 'stdin'
include '0' and
# 0. the other stdio streams have similar shortcuts
#
require 'systemu'

cat = %q( ruby -e" ARGF.each{|line| puts line} " )

status = systemu cat, 0=>'the stdin for cat', 1=>stdout=''
puts stdout

~ > ruby samples/c.rb

the stdin for cat


<========< samples/d.rb >========>

~ > cat samples/d.rb

#
# the cwd can be supplied
#
require 'systemu'
require 'tmpdir'

pwd = %q( ruby -e" STDERR.puts Dir.pwd " )

status = systemu pwd, 2=>(stderr=''), :cwd=>Dir.tmpdir
puts stderr


~ > ruby samples/d.rb

/private/tmp


<========< samples/e.rb >========>

~ > cat samples/e.rb

#
# any environment vars specified are merged into the child's
environment
#
require 'systemu'

env = %q( ruby -r yaml -e" puts ENV[ 'answer' ] " )

status = systemu env, 1=>stdout='', 'env'=>{ 'answer' =>
0b101010 }
puts stdout

~ > ruby samples/e.rb

42


<========< samples/f.rb >========>

~ > cat samples/f.rb

#
# if a block is specified then it is passed the child pid and
run in a
# background thread. note that this thread will __not__ be
blocked during the
# execution of the command so it may do useful work such as
killing the child
# if execution time passes a certain threshold
#
require 'systemu'

looper = %q( ruby -e" loop{ STDERR.puts Time.now.to_i; sleep
1 } " )

status, stdout, stderr =
systemu looper do |cid|
sleep 3
Process.kill 9, cid
end

p status
p stderr

~ > ruby samples/f.rb

#<Process::Status: pid=1012,signaled(SIGKILL=9)>
"1196982119\n1196982120\n1196982121\n"


enjoy.


a @ http://codeforp...
--
it is not enough to be compassionate. you must act.
h.h. the 14th dalai lama




1 Answer

Adam H. Kerman

11/6/2013 4:12:00 PM

0

suzeeq <suzee@imbris.com> wrote:
>Adam H. Kerman wrote:
>>Stan Brown <the_stan_brown@fastmail.fm> wrote:

>>>Glad to see this one was much better than the forgettable one from
>>>last week.

>>The crossposting of discussion of this show pisses me off. You absolutely
>>had to have your own newsgroup? Fine. Discuss it there. Don't cross post
>>into the general tv newsgroup. But gawd forbid last week when I tried to
>>start a thread in rec.arts.sf.tv, several of you refused to post followups
>>there, instead tried to force the thread into two newsgroups I hadn't
>>posted to.

>>If you crosspost, it demonstrates that there's no purpose for the show
>>specific newsgroup to exist and that the author isn't supporting the
>>health of the show-specific newsgroup. Different newsgroups are supposed
>>to have different cultures due to different sets of people in them. There's
>>nothing wrong with that. Constant crossposting kills the culture of the
>>smaller group.

>>Crossposting defeats that. Choose one of the general newsgroups or the
>>show-specific newsgroups, not both. If you think both groups might
>>benefit, start separate non-crossposted threads.

>Some servers may not carry the show specific group. Go grouch on another
>thread Adam.

If the group hasn't been created locally, request it. Doesn't change my
feelings about crossposting, or how my non-thread thread was treated
last week.

Crossposting sucks.