# Shell command execution problem!

**URL:** <https://www.ruby-forum.com/t/shell-command-execution-problem/168445>\
**Category:** Rails\
**Created:** [May 20, 2009, 9:48pm UTC](https://www.ruby-forum.com/t/shell-command-execution-problem/168445 "2009-05-20T21:48:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CiriusMex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@CiriusMex](https://www.ruby-forum.com/u/CiriusMex)\
**Post date:** [May 20, 2009, 9:48pm UTC](https://www.ruby-forum.com/t/shell-command-execution-problem/168445/1 "2009-05-20T21:48:51Z")

</div>

Hi, well here comes my problem. I’m working on a function that will  
generate PDF files automatically using files already existing. I’m  
using pdftk utils to generate those files and everythings is working  
just fine when testing in localhost on my laptop (I’m running windows  
vista on it). But when I come to deploy the application on my server  
(unix of course) and test the function, nothing occurs, seems that the  
function is not executed (I don’t even have a error message…). here  
comes the code for the execution of the function:

# Merging front page and PDF

system("#{RAILS\_ROOT}/public/products/pdftk #{RAILS\_ROOT}/public/  
orders/order#{order.id}/products/frontPage#{product.id}.pdf #  
{RAILS\_ROOT}/public/products/#{formatedProductName}.pdf cat output #  
{RAILS\_ROOT}/public/orders/order#{params[:id]}/products/finalPDF#  
{product.id}.pdf")

while !File.exist?("#{RAILS\_ROOT}/public/orders/order#{params[:id]}/  
products/finalPDF#{product.id}.pdf")  
# We wait…  
end

RAILS\_DEFAULT\_LOGGER.info("\n\n#{RAILS\_ROOT}/public/orders/order#  
{params[:id]}/products/finalPDF#{product.id}.pdf created\n")

# Generating password protected PDF

system("#{RAILS\_ROOT}/public/products/pdftk #{RAILS\_ROOT}/public/  
orders/order#{params[:id]}/products/finalPDF#{product.id}.pdf output #  
{RAILS\_ROOT}/public/orders/order#{params[:id]}/products/#  
{formatedProductName}_#{params[:firstname].tr(’’’,’’)}_#{params  
[:lastname].tr(’’’,’’)}.pdf owner\_pw #{adminAccessPassword} user\_pw #  
{customerAccessPassword}")

while !File.exist?("#{RAILS\_ROOT}/public/orders/order#{params[:id]}/  
products/#{formatedProductName}_#{params[:firstname].tr(’’’,’’)}_#  
{params[:lastname].tr(’’’,’’)}.pdf")  
# We wait…  
end

The files and paths are correct, I verified several times. pdftk is  
correctly installed on the server (I tested executing those two  
commands manualy on the server, it worked perfectly and I could get  
the files generated).

It’s pretty urgent, I’ve tested changing “system” for backquotes and  
nothing. Any idea would be welcome ^^?

Olivier.

---

<div class="post-metadata">

**Author:** ![CiriusMex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@CiriusMex](https://www.ruby-forum.com/u/CiriusMex)\
**Post date:** [May 21, 2009, 9:32pm UTC](https://www.ruby-forum.com/t/shell-command-execution-problem/168445/2 "2009-05-21T21:32:07Z")

</div>

What user is your Rails app running as on the server? That would be my  
first suspect…

–Matt J.

---

<div class="post-metadata">

**Author:** ![CiriusMex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@CiriusMex](https://www.ruby-forum.com/u/CiriusMex)\
**Post date:** [May 21, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/shell-command-execution-problem/168445/3 "2009-05-21T21:45:38Z")

</div>

try piping it to STDOUT see if you get anywhere. Ex:  
sh.system(“ls”, “-l”) | sh.head \> STDOUT

---

<div class="post-metadata">

**Author:** ![CiriusMex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/90ced4/32.png) [@CiriusMex](https://www.ruby-forum.com/u/CiriusMex)\
**Post date:** [May 21, 2009, 11:45pm UTC](https://www.ruby-forum.com/t/shell-command-execution-problem/168445/4 "2009-05-21T23:45:49Z")

</div>

Ok, thanks for the help, I changed the path for the system command  
execution and did the trick, I don’t really know what was the problem  
but hope it won’t come back…^^

Anyway, thanks for taking time to respond to my question 😉

Olivier.
