Board index » ruby
All times are UTC
def command ( the_command ) t = Thread.new do sin, sout, serr = Open3.popen3( the_command ) sout.each_line { |line| puts line } # prints output to stdout
sout.close end # of Thread
end # def command
> end # def command
I'd try getting rid of the the each_line code.
I just realised what the problem is! You've been bitten by the "threads don't abort on exception" problem that has caused me confusion about fifty times now.
The real issue is that you need a "require 'open3'" at the top.
What's happening is that the thread is throwing an exception, because Open3 is an undefined symbol, but you can't see that's happening, because, by default, when a thread throws an exception, it just dies quietly, rather than aborting with a stack trace.
I recommend setting Thread.abort_on_exception to true during your testing phase for any new thread code. Once you're happy that it's "always" going to be OK, take that out.
Anyway, sticking the require at the top should sort it out, but as I said previously, you'll probably want to get rid of the each_line code, otherwise your var won't end up with any data.
I think I've mentioned before that I think the default should be that abort_on_exception is true, because it causes confusion every time I write multithreaded code ... of course, maybe most people are smarter than me and learn after the third or fourth time :-).
I was paying no attention to what the main thread did. For some stupid reason I was assuming (duh!) that it blocked. I've been trying to read uninitialized data.
I didn't see that until I laced the whole program with print statements and watched the control flow rather differently from what I expected.
I bet it's going to work right when I get the execution flow in the main thread fixed.
Well, I learned something!
Eirikur
1. naive type checking II (not so naive?)
2. Questions from a naive user
3. Questions from a naive st programmer
4. Naive Forth questions
5. Extremely naive (and probably stupid) question
6. (Yet another) naive question
7. Naive question
8. Naive question
9. Another naive question
10. Naive Number Question
11. Naive Number Question
12. Naive newbie question.