i am using a ruby script to generate PDF files, which i always open by hand afterwards to print them.
Is there a way to do this automatically from the script (to open them)?
I googled a bit and found exec(), but this does not seem to work for non-exe files:
generate.rb:624:in `exec': Exec format error - test.pdf (Errno::ENOEXEC)
from generate.rb:624:in `<main>'
Also, the generated PDF is one folder above where the script is. How could i address the file in a relative way? exec("../whatever.pdf")? This approach ended in:
generate.rb:624:in `exec': No such file or directory - ../test.pdf (Errno::ENOENT)
from generate.rb:624:in `<main>'
I also tried spawn, same results.
I am using Windows 10, and would like to have the PDF started by whatever tool is set as standard in Windows. Is there a way to do this? Any help is very appreciated.
Thanks
If your file is one folder above the current folder then we need to get the parent folder of the current directory and then append the file name to it.To get the file path you can use
file_path = File.expand_path("..", Dir.pwd) + '/filename.pdf'
And I assume you want to open the pdf in Pdf reader after creating it using ruby. Try this option.
system ('start "" "file_path\filename.pdf"')
The final code would be like this
filepath = File.expand_path("..", Dir.pwd) + "/filename.pdf"
str = 'start "" "' + "#{filepath}" + '"'
system (str)