title: Running a system command (pdflatex) within my Rails Controller
body: <p>So I have a Rails application that upon user submission should generate some kind of a .tex file based on the user input, compile it into a pdf, and deliver the pdf. Through process of elimination, I am pretty positive that everything is working except for one line; the one where pdflatex is called.</p>
  
  <p>Here's the vital snippet of code:
  (If it matters, its located in the Questions controller under the generate action, which is called after the form sends the relevant information. Though this may not be the best way, I'm pretty certain its not the cause of the error)</p>
  
  <pre><code>texHeader = 'app\assets\tex\QuestionsFront.txt' 
  texOut = 'app\assets\tex\Questions.tex'
  
  #copy latex header to new file
  FileUtils.cp(texHeader, texOut)
  
  File.open(texOut, 'a+') do |fout|
        fout.write("\n")
           # a loop writes some more code to fout (its quite lengthy)
        fout.write("\\end{enumerate}\n")
        fout.write("\\end{document}")
        #The problem line:
        puts `pdflatex app/assets/tex/Questions.tex --output-directory=app/assets/tex`
      end
  
      filename = 'Questions.pdf'
      filelocation = "app\\assets\\tex\\" + filename
  
      File.open(filelocation, 'r') do |file|
        send_file file, :filename =&gt; filename, :type =&gt; "application/pdf", :disposition =&gt; "attachment"
      end
  end
  </code></pre>
  
  <p>Here's my reasoning: It generates the .tex file correctly, and given a pre-created Questions.pdf file it sends it just fine.  When the command in the puts is copied to the terminal, it runs without a hitch (the file begins with \nonstopmode so no worries about small errors).  But for some reason, when I run the above script, not even a log file is created with an error.</p>
  
  <p>What am I overlooking? Any ideas? Any way of seeing what output the puts line is creating?</p>
  
  <p>Thanks so much in advance!</p>