From kluczka@o2.pl Sun Mar 21 16:46:24 2010 From: hugos To: textmate@lists.macromates.com Subject: [TxMt] Problem with real-time presenting standard output (cout) in HTML output Date: Sun, 21 Mar 2010 09:46:21 -0700 Message-ID: <27976999.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3209753160731495464==" --===============3209753160731495464== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable I wrote a program in C++ which does some long calculations. For information purpose it has a "cout" function which tels me about a progress of evaluation. I'm used to compile my program via TM with my own boundle-command script which looks like that: ------------------------------------------------------------ echo "
"=20

make | pre

find_name=3D"grep 'NAME=3D' ./makefile | cut -c 6- "
cmd=3D `eval $find_name | awk '{print "./"$0}'`
$cmd

echo "
" ------------------------------------------------------------ My problem is that the standard output (text that "cout" presents) is shown at once after program is finished (but non during program is running) so I don't see progress of calculation. Is there a way for presenting standard output in these case (in real-time)? --=20 View this message in context: http://old.nabble.com/Problem-with-real-time-pr= esenting-standard-output-%28cout%29-in-HTML-output-tp27976999p27976999.html Sent from the textmate users mailing list archive at Nabble.com. --===============3209753160731495464==-- From my2ndaddress@gmail.com Sun Mar 21 17:15:18 2010 From: chris To: textmate@lists.macromates.com Subject: [TxMt] Re: Problem with real-time presenting standard output (cout) in HTML output Date: Sun, 21 Mar 2010 17:15:14 +0000 Message-ID: <274d9c291003211015ge9e0eb5gb62e144b2d7277b6@mail.gmail.com> In-Reply-To: <27976999.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3277288932314427653==" --===============3277288932314427653== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable maybe try: if ($ENV{'TM_PID'}) { $| =3D 1 }; at the start of your script. Which I ripped out of another thread: Alex Ross date Mon, Mar 8, 2010 at 3:46 AM subject [TxMt] Re: Interactive input in Textmate (for Perl) -chris On Sun, Mar 21, 2010 at 4:46 PM, hugos wrote: > > I wrote a program in C++ which does some long calculations. For information > purpose it has a "cout" function which tels me about a progress of > evaluation. > I'm used to compile my program via TM with my own boundle-command script > which looks like that: > ------------------------------------------------------------ > echo "
"
>
> make | pre
>
> find_name=3D"grep 'NAME=3D' ./makefile | cut -c 6- "
> cmd=3D `eval $find_name | awk '{print "./"$0}'`
> $cmd
>
> echo "
" > ------------------------------------------------------------ > My problem is that the standard output (text that "cout" presents) is shown > at once after program is finished (but non during program is running) so I > don't see progress of calculation. > > Is there a way for presenting standard output in these case (in real-time)? > -- > View this message in context: http://old.nabble.com/Problem-with-real-time-= presenting-standard-output-%28cout%29-in-HTML-output-tp27976999p27976999.html > Sent from the textmate users mailing list archive at Nabble.com. > > > _______________________________________________ > textmate mailing list > textmate(a)lists.macromates.com > http://lists.macromates.com/listinfo/textmate --===============3277288932314427653==-- From matt@tidbits.com Sun Mar 21 17:25:19 2010 From: matt@tidbits.com To: textmate@lists.macromates.com Subject: [TxMt] Re: Problem with real-time presenting standard output (cout) in HTML output Date: Sun, 21 Mar 2010 10:25:00 -0700 Message-ID: <1jfp86y.re4eloc6yadoN%matt@tidbits.com> In-Reply-To: <27976999.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7030549441600651957==" --===============7030549441600651957== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit hugos wrote: > I wrote a program in C++ which does some long calculations. For information > purpose it has a "cout" function which tels me about a progress of > evaluation. > I'm used to compile my program via TM with my own boundle-command script > which looks like that: > ------------------------------------------------------------ > echo "
" 
> 
> make | pre
> 
> find_name="grep 'NAME=' ./makefile | cut -c 6- "
> cmd= `eval $find_name | awk '{print "./"$0}'`
> $cmd
> 
> echo "
" > ------------------------------------------------------------ > My problem is that the standard output (text that "cout" presents) is shown > at once after program is finished (but non during program is running) so I > don't see progress of calculation. > > Is there a way for presenting standard output in these case (in real-time)? The first thing to try is getting rid of the
 tags, since these
explicitly *prevent* output from appearing in real time. 

If that works, then you may notice that you're losing the formatting
advantage of using 
. You can work around this, and keep the 
,
by appending 
tags to each line as it appears, but to do that you're probably going to need to pipe your output through something else. For example, what I do (since Ruby is what I happen to use) is wrap the call to my script in a Ruby script which redirects stdout to pass thru my own class. Here are some relevant excerpts: require "#{ENV["TM_SUPPORT_PATH"]}/lib/web_preview.rb" require "#{ENV["TM_SUPPORT_PATH"]}/lib/escape.rb" def write(s) s = htmlize(s, :no_newline_after_br => true) @old_stdout.print s end So, what happens is as output occurs it is passed to me, because I am substituting myself for stdout. (Heh heh.) Meanwhile the real stdout has been saved as @old_stdout. So my write() is called (because I appear to be stdout), I fix up the output with a
using TextMate's built-in htmlize(), and then pass the line on out to the real stdout, thus causing it to appear in TextMate's output window, in real time. So you might be able to set up a pipe that does something similar. There are buffering issues, of course, which are too elaborate to discuss here... :) m. -- matt neuburg, phd = matt(a)tidbits.com A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings --===============7030549441600651957==--