Running php from RoR

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'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

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

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

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.

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