run a ruby script and use the standard output ???
Hi all, Is it possible to run a ruby script from a context document during its processing (I already know how to do that using \write18 but there is maybe a better way...) then get the output of the script to display or use it into the document. It's a little bit hard to describe so I have a simple example: \starttext \def\vartest{3.124325234543523452435} \write18{ruby ./myscript.rb \vartest XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX} \stoptext with myscript.rb: temp = ARGV[0] puts "\nXXXXXXXXXXXXX " + (Math::sqrt(temp.to_f)).to_s + " XXXXXXXXXXXXX\n" I would store the result of puts into a variable usable within ConTeXt... Renaud
Renaud AUBIN wrote:
Hi all,
Is it possible to run a ruby script from a context document during its processing (I already know how to do that using \write18 but there is maybe a better way...) then get the output of the script to display or use it into the document. It's a little bit hard to describe so I have a simple example:
\starttext \def\vartest{3.124325234543523452435} \write18{ruby ./myscript.rb \vartest XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX} \stoptext
with myscript.rb:
temp = ARGV[0] puts "\nXXXXXXXXXXXXX " + (Math::sqrt(temp.to_f)).to_s + " XXXXXXXXXXXXX\n"
I would store the result of puts into a variable usable within ConTeXt...
piping: the latest versions of pdftex support this (i\ve forgotten the syntax, but taco who wrote the patch may remember) you can also let ruby write a definition to a file temp.tmp which you can read in however, luatex can do: \edef\SomeVar{\lua{tex.print(math.sqrt(3.124325234543523452435))} or \def\GimmeARoot#1{\lua{tex.print(math.sqrt(#1))} actually, this is one of the examples i use in prelim demos at user group meetings -) so, be a bit patient and it will come your way ... Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans Hagen wrote:
piping: the latest versions of pdftex support this (i\ve forgotten the syntax, but taco who wrote the patch may remember)
piping syntax: \input "|ruby ./myscript.rb \vartest XXXXXXXXX" the magic trick is the | symbol. With your current tex: \writ18{ruby ./myscript.rb \vartest XXXXXXXXX > whatever.tex} \input whatever % or something using \openin ... Taco
\starttext \input "|ls" \stoptext leads to (/usr/share/texmf-tetex/tex/latex/tools/.tex File ignored) Runaway argument? ls" ! Paragraph ended before \next was complete. <to be read again> \par ??? Taco Hoekwater a écrit :
Hans Hagen wrote:
piping: the latest versions of pdftex support this (i\ve forgotten the syntax, but taco who wrote the patch may remember)
piping syntax:
\input "|ruby ./myscript.rb \vartest XXXXXXXXX"
the magic trick is the | symbol. With your current tex:
\writ18{ruby ./myscript.rb \vartest XXXXXXXXX > whatever.tex} \input whatever % or something using \openin ...
Taco _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Renaud AUBIN wrote:
\starttext
\catcode`\|=12 \input "|ls -l"
\stoptext
! I can't find file `"|ls -l"'.
And all you need now is the latest pdftex -) http://sarovar.org/project/showfiles.php?group_id=106&release_id=752 Taco
Taco Hoekwater a écrit :
And all you need now is the latest pdftex -)
http://sarovar.org/project/showfiles.php?group_id=106&release_id=752
Taco
Thanks Yes, I finally realized that... ;) I'm now on my way to upgrade it...
Taco Hoekwater a écrit :
And all you need now is the latest pdftex -)
http://sarovar.org/project/showfiles.php?group_id=106&release_id=752
Taco
Is it normal that pdfetex.pool is no more built ?
Renaud AUBIN wrote:
Taco Hoekwater a écrit :
And all you need now is the latest pdftex -)
http://sarovar.org/project/showfiles.php?group_id=106&release_id=752
Taco
Is it normal that pdfetex.pool is no more built ?
Yes. There is now only one executable, pdftex. It contains all code that was previously in pdfetex and the `bare' pdftex is gone. Taco
participants (3)
-
Hans Hagen
-
Renaud AUBIN
-
Taco Hoekwater