Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

catching a system call output

0 views
Skip to first unread message

Tool69

unread,
Nov 7, 2005, 11:36:38 AM11/7/05
to
Hi,
I've a Ruby prog with a system call to latex like this one :
system('latex -interaction=nonstopmode temp.tex')
It works fine, but I wanted to catch the output inside an array (or
variable), but not in my terminal.
How can I do that ? Thanks for your response :
6TooL9

Sean O'Halpin

unread,
Nov 7, 2005, 11:40:58 AM11/7/05
to

You can use backticks to capture stdout:

text = `latex -interaction=nonstopmode temp.tex`

Regards,

Sean


Brian Schröder

unread,
Nov 7, 2005, 11:42:06 AM11/7/05
to

Try

output = `latex -interaction=nonstopmode temp.tex`

(note that the symbols above are backticks, not quotation marks)

or dive into popen.

cheers,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/


Hugh Sasse

unread,
Nov 7, 2005, 11:53:11 AM11/7/05
to

open('|latex -interaction=nonstopmode temp.tex') do |stream|
#then maybe...
stream.readlines.each do |line
end
end

See also IO.popen, and others [cf Ruby-Talk:163897]

> 6TooL9
>
>
Hugh
>

Tool69

unread,
Nov 7, 2005, 12:50:14 PM11/7/05
to
Thank you very much for your answers, I'll try them. I've just received
my book on ruby "Programming Ruby, 2nd Ed" , I think that it will be
very useful!
6TooL9

Tool69

unread,
Nov 7, 2005, 1:43:10 PM11/7/05
to
So it works perfectly, but I got one more question :
what can I do if I have a variable inside my system call, like :
system("latex -interaction=nonstopmode #{@myvar}")
I tried with backticks, but it doesn't seems to work :
`latex -interaction=nonstopmode #{@myvar}`
Any solution ? Thanks again !

Brian Schröder

unread,
Nov 7, 2005, 2:13:31 PM11/7/05
to
On 07/11/05, Tool69 <kibleur.c...@gmail.com> wrote:

Works for me:
$ ruby -e 'test = 42; p `echo "#{test}"`'
"42\n"

Tool69

unread,
Nov 7, 2005, 2:27:36 PM11/7/05
to
Thanks Brian, I forgot the "" inside !

0 new messages