Prev | Current Page 231 | Next

David Berube

"Practical Reporting with Ruby and Rails"

puts html
process_handle.close_write
CHAPTER 8 n CREATING SALES PERFORMANCE REPORTS WITH SUGARCRM 167
ps_source = process_handle.read
end
pdf_source = ''
open('|"' + path_to_ps2pdf +'" - -', 'wb+') do |process_handle|
process_handle.puts ps_source
process_handle.close_write
pdf_source = process_handle.read
end
This code does not use temporary files, which are the most obvious way to communicate
with an outside process; instead, the block of code uses pipes. Specifically, the open
call lets you open an arbitrary file, a URI, or a pipe to a process, and the pipe at the beginning
of the argument to open lets Ruby know that you intend to open a process. You can
then use the pipe to that process to read and write to it as if it were a file, but instead of
writing to a file, you send input to the program as if it were typed into the program by the
user. Conversely, when you read, the output from the program is read into your program
instead of being displayed on the screen. This process lets you eliminate the temporary
files, and read and write directly from the program.


Pages:
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
free mp3 Mietek Szcześniak ochrona Emmanuel Moire Little Eva