I have a controller method written along these lines: begin system("/script/that/generates/output > text_file") var += IO.readlines("text_file") send_data var, :filename => "attachment.txt", :disposition => ''attachment'', :type => ''text/plain'' rescue flash[:error] = "Error message here" redirect_to :action => ''error_page'' end What this is supposed to do is send the contents of the text file plus some other data directly to the user. The problem is, of course, that the system call will not run from a Rails controller as this is apparently considered very naughty. I could instead use backgroundrb to generate the file (the same system call is fine as part of a backgroundrb job) and then e-mail it to users but I would rather send it immediately as the attachment is virtually instantaneous. Is backgroundrb really the only way to do that? It seems a bit much for such a small task. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Milo, Milo Thurston wrote:> The problem is, of course, that the system call will > not run from a Rails controller as this is apparently > considered very naughty.I''m not sure what you''re talking about. You can make system calls. To test, in a list method in a controller, put the line system(''dir > dir_test.txt'') or the equivalent depending on what OS you''re using. You should find the file in the app root directory. You might want to check your log files to see what they tell you about your current situation. HTH, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> I''m not sure what you''re talking about. You can make system calls.I did a search of this group and found advice against system calls.> You might want to check your log files to see what they tell you about > your > current situation.They tell me absolutely nothing, unfortunately. The system call fails with no message in the logs, and yet I can run the same system call successfully on the command line as the same user. My assumption was that system calls were not allowed but perhaps I was mistaken and there is something else very strange going on. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Milo, Milo Thurston wrote:> The system call fails with no message in the logs, > and yet I can run the same system call successfully > on the command line as the same user.When you say ''fails'' I assume you mean you just can''t find the file you expect to be created anywhere on your system. If there''s something visible happening that you can report, it would help. When you say ''on the command line'', do you mean from irb or script\console ? Or do you mean ''from the OS command line''? If the latter, it''s potentially a permissions issue. Note that your rails app runs as a different user than you. Try to run it as that user and see what happens. HTH, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote;> When you say ''fails'' I assume you mean you just can''t find the file you > expect to be created anywhere on your system.That''s part of it. I tried setting things up as in this pseudocode: begin logger.info("ONE") first system call logger.info("TWO") second system call logger.info("THREE") rescue redirect to the error page end In this case the expected file does not appear, "ONE" is found in the log but not "TWO" or "THREE", and the app. redirects to the error page. It seems that the system call is a complete failure with no explanation.> When you say ''on the command line'', do you mean from irb or > script\console ? > Or do you mean ''from the OS command line''? If the latter, it''s > potentially > a permissions issue.I tried it on the OS command line. I thought that it might be permissions, but I''d run script/server as a user that has write permission to the relevant directory. I''d also expect some sort of permissions error in the logs from the system call but none were to be found. I hadn''t tried it with irb or script/console but I just did and it worked as expected. Very odd... Thanks for taking the time to make some suggestions! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Sep 23, 2008 at 1:57 AM, Milo Thurston <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Bill Walton wrote; >> When you say ''fails'' I assume you mean you just can''t find the file you >> expect to be created anywhere on your system. > > That''s part of it. I tried setting things up as in this pseudocode: > > begin > logger.info("ONE") > first system call > logger.info("TWO") > second system call > logger.info("THREE") > rescue > redirect to the error page > end > > In this case the expected file does not appear, "ONE" is found in the > log but not "TWO" or "THREE", and the app. redirects to the error page. > It seems that the system call is a complete failure with no explanation. > >> When you say ''on the command line'', do you mean from irb or >> script\console ? >> Or do you mean ''from the OS command line''? If the latter, it''s >> potentially >> a permissions issue. > > I tried it on the OS command line. I thought that it might be > permissions, but I''d run script/server as a user that has write > permission to the relevant directory. I''d also expect some sort of > permissions error in the logs from the system call but none were to be > found. I hadn''t tried it with irb or script/console but I just did and > it worked as expected. Very odd... > > Thanks for taking the time to make some suggestions! >Rather than using system() you can use backticks `echo "hello"` to capture output of a command, which will tell you more about, what happened to the call. Also, in rails system() or `` backticks are only not advised, when they end up blocking the master mongrel process for a real long time, otherwise you can happily use system() or `` within your programs without problems. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hemant Kumar wrote:> Also, in rails system() or `` backticks are only not advised, when > they end up blocking the master mongrel process for a real long time, > otherwise you can happily use system() or `` within your programs > without problems.Thanks - evidently I had jumped to the wrong conclusion. It looks like one of the object methods included in #{} within the system call is failing; it''s strange that there''s no error message but that must be the cause. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 23, 1:43 am, Milo Thurston <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thanks - evidently I had jumped to the wrong conclusion. > It looks like one of the object methods included in #{} within the > system call is failing; it''s strange that there''s no error message but > that must be the cause.Sometimes exception handling code can eat useful error messages, especially if you don''t capture and display the exception object, you may miss useful info. When diagnosing things, I occasionally find it is useful to comment out the rescue clause and let the error bubble to the surface. Alternatively, capture it (e.g. rescue Exception => e) and display in your rescue clause with a logger or similar output. -c --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Haupt wrote:> Alternatively, capture it (e.g. rescue Exception => e) > and display in your rescue clause with a logger or similar output.A very useful suggestion - thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---