Back from the conference and eager to learn Ruby, I’m trying to write a
tool for grepping the table of contents of jar files. (I have a similar
Bourne shell script, but I want to add some features and start small
learning Ruby). I have something working, but in trying to restructure
it, I’ve encountered a problem with Shell#transact when using it inside
an instance method of a class. In both cases, I’ve used
Shell#def_system_command to define jar and grepcmd like this:
Shell.def_system_command "jar"
Shell.def_system_command "grepcmd", "grep"
If I have a “plain” script (i.e. no class definition or methods), I have
no problem with the following:
sh = Shell.new
ARGV.each { |jarfile|
sh.transact do
results = jar("tf", jarfile) | grepcmd(pattern)
puts results
end
}
However, if I try to put this in an instance method (see next code
snippet), it never returns and starts taking 100% of my CPU until I kill
it.
class JarGrepper
attr_writer :pattern
def jartoc(jarfile)
sh = Shell.new
sh.transact do
results = jar("tf", jarfile) | grepcmd(@pattern)
puts results
end
end
end
If I take out the transact (see next code snippet), it works, but I get
warnings:
class JarGrepper
attr_writer :pattern
def jartoc(jarfile)
sh = Shell.new
results = sh.jar("tf", jarfile) | sh.grepcmd(@pattern)
puts results
end
end
Here are the warnings:
shell: notice: Process finishing...
wait for Job[grep:#6293] to finish.
You can use Shell#transact or Shell#check_point for more safe
execution.
shell: notice: Process finishing...
wait for Job[jar:#6292] to finish.
You can use Shell#transact or Shell#check_point for more safe
execution.
What I’d like to be able to do is to get the results of ‘jar(“tf”,
jarfile) | grepcmd(@pattern)’ from within an instance method and without
warnings.
In case it’s relevant, I’m running Ruby 1.6.7 on Red Hat Linux 7.2.
Thanks in advance for any help or explanations,
Xandy