Hello... I am trying to execute a php script from within rails. The action is triggered by a button. def load_stock if result = system(''php test.php'') flash[:notice] = result end end However, it keeps returning false. If I run the command from the Windows command line it works. Any ideas? Thank you. GPB --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You''re not telling us what environment you''re running this under. It''s possible that you''re running into issues with permissions, apache, or otherwise. Also, if you run "system", you won''t get a result. The running environment is temporarily replaced while the system call executes. I assume you''re trying to get the perl-like behavior of: $foo = `some command` Rails isn''t going to work in the same way. -j On Dec 5, 2007, at 3:56 AM, GPB wrote:> > > Hello... > > I am trying to execute a php script from within rails. > > The action is triggered by a button. > > def load_stock > if result = system(''php test.php'') > flash[:notice] = result > end > end > > However, it keeps returning false. > > If I run the command from the Windows command line it works. > > Any ideas? > > Thank you. > > GPB >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
backticks exist in ruby too, and you''ll get back the output of the command which may be useful in working out what''s gone wrong. The most likely thing is the the current directory isn''t what you think it is (ie test.php isn''t in it) Fred On 5 Dec 2007, at 12:12, John Adams wrote:> > You''re not telling us what environment you''re running this under. > > It''s possible that you''re running into issues with permissions, > apache, or otherwise. Also, if you run "system", you won''t get a > result. > > The running environment is temporarily replaced while the system call > executes. I assume you''re trying to get the perl-like behavior of: > > $foo = `some command` > > Rails isn''t going to work in the same way. > > -j > > On Dec 5, 2007, at 3:56 AM, GPB wrote: > >> >> >> Hello... >> >> I am trying to execute a php script from within rails. >> >> The action is triggered by a button. >> >> def load_stock >> if result = system(''php test.php'') >> flash[:notice] = result >> end >> end >> >> However, it keeps returning false. >> >> If I run the command from the Windows command line it works. >> >> Any ideas? >> >> Thank you. >> >> GPB >> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello John, Thank you for replying. I am running this under a Windows 2003 Server, using Mongrel, Ruby on Rails 1.2.5. I am interested in getting the php script running, not so much returning a value. The php script is supposed to run some queries against an AS/400 to update a table. I would like to do this only in Rails but I couldn''t get the ODBC connector to work, it seems it doesn''t support the AS/400 database system. In the past I have been successful doing this with PHP, so I''m trying this approach of triggering the php script from within the Rails application. Thanks, GPB On Dec 5, 1:12 pm, John Adams <j...-v/oBC7Wj0TusTnJN9+BGXg@public.gmane.org> wrote:> You''re not telling us what environment you''re running this under. > > It''s possible that you''re running into issues with permissions, > apache, or otherwise. Also, if you run "system", you won''t get a result. > > The running environment is temporarily replaced while the system call > executes. I assume you''re trying to get the perl-like behavior of: > > $foo = `some command` > > Rails isn''t going to work in the same way. > > -j > > On Dec 5, 2007, at 3:56 AM, GPB wrote: > > > > > > > Hello... > > > I am trying to execute a php script from within rails. > > > The action is triggered by a button. > > > def load_stock > > if result = system(''php test.php'') > > flash[:notice] = result > > end > > end > > > However, it keeps returning false. > > > If I run the command from the Windows command line it works. > > > Any ideas? > > > Thank you. > > > GPB- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 Frederick, Thanks for replying. I have also tried... result = system(''php c:/test.php'') Same problem. This runs on the command line, but not when called from RoR it returns false. But I went with your advice and started to use backticks and at least I got something back when running the windows command "ver". So I think I am on the right track. Will keep trying. Thank you. On Dec 5, 1:17 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> backticks exist in ruby too, and you''ll get back the output of the > command which may be useful in working out what''s gone wrong. > The most likely thing is the the current directory isn''t what you > think it is (ie test.php isn''t in it) > > Fred > > On 5 Dec 2007, at 12:12, John Adams wrote: > > > > > > > You''re not telling us what environment you''re running this under. > > > It''s possible that you''re running into issues with permissions, > > apache, or otherwise. Also, if you run "system", you won''t get a > > result. > > > The running environment is temporarily replaced while the system call > > executes. I assume you''re trying to get the perl-like behavior of: > > > $foo = `some command` > > > Rails isn''t going to work in the same way. > > > -j > > > On Dec 5, 2007, at 3:56 AM, GPB wrote: > > >> Hello... > > >> I am trying to execute a php script from within rails. > > >> The action is triggered by a button. > > >> def load_stock > >> if result = system(''php test.php'') > >> flash[:notice] = result > >> end > >> end > > >> However, it keeps returning false. > > >> If I run the command from the Windows command line it works. > > >> Any ideas? > > >> Thank you. > > >> GPB- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 Frederick, OK, backticks did the trick. Thank you. But it seems Ruby doesn''t find php.exe even though it''s in the Windows path, so I need to call it using the windows path. result = `c:/progra~1/php/php c:/test.php` Thanks again for your help. GPB On Dec 5, 1:59 pm, GPB <gbar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Frederick, > > Thanks for replying. > > I have also tried... > > result = system(''php c:/test.php'') > > Same problem. This runs on the command line, but not when called from > RoR it returns false. > > But I went with your advice and started to use backticks and at least > I got something back when running the windows command "ver". > > So I think I am on the right track. Will keep trying. > > Thank you. > > On Dec 5, 1:17 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > backticks exist in ruby too, and you''ll get back the output of the > > command which may be useful in working out what''s gone wrong. > > The most likely thing is the the current directory isn''t what you > > think it is (ie test.php isn''t in it) > > > Fred > > > On 5 Dec 2007, at 12:12, John Adams wrote: > > > > You''re not telling us what environment you''re running this under. > > > > It''s possible that you''re running into issues with permissions, > > > apache, or otherwise. Also, if you run "system", you won''t get a > > > result. > > > > The running environment is temporarily replaced while the system call > > > executes. I assume you''re trying to get the perl-like behavior of: > > > > $foo = `some command` > > > > Rails isn''t going to work in the same way. > > > > -j > > > > On Dec 5, 2007, at 3:56 AM, GPB wrote: > > > >> Hello... > > > >> I am trying to execute a php script from within rails. > > > >> The action is triggered by a button. > > > >> def load_stock > > >> if result = system(''php test.php'') > > >> flash[:notice] = result > > >> end > > >> end > > > >> However, it keeps returning false. > > > >> If I run the command from the Windows command line it works. > > > >> Any ideas? > > > >> Thank you. > > > >> GPB- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---