My bundle command, written in Ruby, looks like this:
s = #... command-line command that produces many lines of output STDOUT.sync = true puts '<pre>' puts `#{s}` puts '</pre>'
It is set to output as HTML. In TextMate 1, the result was correctly formatted: line after line of text, wrapped in <pre> tags, wrapped in HTML. In TextMate 2, the opening and closing <pre> tags both appear before the output from executing s, and thus the output is not correctly formatted.
Clearly something has changed. What's the new correct way of doing this? Thanks - m.
-- matt neuburg, phd = matt@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 7! http://shop.oreilly.com/product/0636920031017.do iOS 7 Fundamentals! http://shop.oreilly.com/product/0636920032465.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
On 7 Jan 2014, at 8:28, Matt Neuburg wrote:
My bundle command, written in Ruby, looks like this:
s = #... command-line command that produces many lines of output STDOUT.sync = true puts '<pre>' puts `#{s}` puts '</pre>'
It is set to output as HTML. In TextMate 1, the result was correctly formatted: line after line of text, wrapped in <pre> tags, wrapped in HTML. In TextMate 2, the opening and closing <pre> tags both appear before the output from executing s, and thus the output is not correctly formatted.
Clearly something has changed. What's the new correct way of doing this? Thanks - m.
This could happen if your command (“s”) outputs to stderr (instead of stdout).
You can either redirect the output to stdout or possibly handle both stdout and stderr from the command via something like popen3 or TextMate::Executor. With the latter, I think you can simply do:
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/executor"
s = #... command-line command that produces many lines of output TextMate::Executor.run(s)
Then the output should be wrapped in the HTML output theme, stderr will appear red, etc.
On Jan 9, 2014, at 7:09 PM, Allan Odgaard mailinglist@textmate.org wrote:
On 7 Jan 2014, at 8:28, Matt Neuburg wrote:
My bundle command, written in Ruby, looks like this:
s = #... command-line command that produces many lines of output STDOUT.sync = true puts '<pre>' puts `#{s}` puts '</pre>'
It is set to output as HTML. In TextMate 1, the result was correctly formatted: line after line of text, wrapped in <pre> tags, wrapped in HTML. In TextMate 2, the opening and closing <pre> tags both appear before the output from executing s, and thus the output is not correctly formatted.
Clearly something has changed. What's the new correct way of doing this? Thanks - m.
This could happen if your command (“s”) outputs to stderr (instead of stdout).
Great suggestion, thanks! As you advised, I dealt with this by calling popen3 (actually I used popen2e):
puts "<pre>" puts "Converting #{f}..." require 'open3' Open3.popen2e(s) do |i,o,t| puts o.read end puts "</pre>"
Unfortunately all the output appears at once; it would be nice to get each line of output to appear as it arrives. But one can't have everything...
TextMate::Executor.run() is worth knowing about, but I couldn't get it to work in this case, as it seems to expect a Ruby file. Thanks again, this worked great. m.
-- matt neuburg, phd = matt@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 7! http://shop.oreilly.com/product/0636920031017.do iOS 7 Fundamentals! http://shop.oreilly.com/product/0636920032465.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
On 11 Jan 2014, at 2:10, Matt Neuburg wrote:
[…] Unfortunately all the output appears at once; it would be nice to get each line of output to appear as it arrives. But one can't have everything...
This has to do with your “o.read”.
TextMate::Executor.run() is worth knowing about, but I couldn't get it to work in this case, as it seems to expect a Ruby file.
It’s not expecting a ruby file, however, it is made for running something via an interpreter and arguments needs to be split up, e.g. this works (tested it):
TextMate::Executor.run("/usr/bin/seq", "10", "5", "50", :use_hashbang => false)
Without the :use_hashbang set to false, it will try to find the interpreter via the last argument (if it’s a file).
There is still a minor issue in that it will initially run the interpreter (first argument) with “--version” to show what version is being used (in the output window). The actual argument can be changed, but there is no way to disable the feature (but there probably should be).
Very helpful, thanks! I really appreciate this kind of education. m.
On Jan 11, 2014, at 8:11 PM, Allan Odgaard mailinglist@textmate.org wrote:
On 11 Jan 2014, at 2:10, Matt Neuburg wrote:
[…] Unfortunately all the output appears at once; it would be nice to get each line of output to appear as it arrives. But one can't have everything...
This has to do with your “o.read”.
TextMate::Executor.run() is worth knowing about, but I couldn't get it to work in this case, as it seems to expect a Ruby file.
It’s not expecting a ruby file, however, it is made for running something via an interpreter and arguments needs to be split up, e.g. this works (tested it):
TextMate::Executor.run("/usr/bin/seq", "10", "5", "50", :use_hashbang => false)
Without the :use_hashbang set to false, it will try to find the interpreter via the last argument (if it’s a file).
There is still a minor issue in that it will initially run the interpreter (first argument) with “--version” to show what version is being used (in the output window). The actual argument can be changed, but there is no way to disable the feature (but there probably should be).
-- matt neuburg, phd = matt@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 7! http://shop.oreilly.com/product/0636920031017.do iOS 7 Fundamentals! http://shop.oreilly.com/product/0636920032465.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
On Jan 11, 2014, at 10:25 PM, Matt Neuburg matt@tidbits.com wrote:
Very helpful, thanks! I really appreciate this kind of education. m.
And the winner is (hey, it might help someone else in the future):
require 'shellwords' require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/executor" a = s.shellsplit TextMate::Executor.run(*a, :use_hashbang => false, :verb => "Converting")
"s" is the big long command-line string. Output looks great, plus it outputs as the messages from the shell arrive (your threading/piping is serious better than mine). Personally I think the "version" display you mentioned earlier looks great too. Thanks again. m.
-- matt neuburg, phd = matt@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 7! http://shop.oreilly.com/product/0636920031017.do iOS 7 Fundamentals! http://shop.oreilly.com/product/0636920032465.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com