3

I have a C program I have compiled to a exe called crunch.

It takes a string and returns a hash string. It has worked for a long time but I just needed to make a small change to it. It works perfectly in terminal as such:

./crunch url-string/with-file.jpg

Spits out a nice hash string. In my php I have been executing it as such:

$crunch = '~/domains/somewhere.net/html/api/crunch';
        $code = `$crunch $code`;
        $code = mysql_real_escape_string(trim($code));

$code is initially a string which is an URL. It has been returning a hash but not any more.

I have recompiled the C a few times. Just don't get it, I have tried php exec() , passthru().

FIXED:

The issue was the difference between my Mac Unix distros and the linux server. The fix was to log into my server and compile the .c file there.

Bobs your Uncle, works again.

Thanks peeps, I did check everyones advice. Sometimes ruling out possible breaks helps focus on the issue. Virtual beers(or sparkling water) all around!

5
  • 1
    Your EXE runs when called outside of PHP, but doesn't run from PHP? That's almost always a permissions problem. Commented Jul 5, 2012 at 8:02
  • Getting any actual errors? Made sure the apache user can execute it? Commented Jul 5, 2012 at 8:03
  • 1
    Are you sure the command line shouldn't be ../crunch.exe instead of just ../crunch? Commented Jul 5, 2012 at 8:10
  • 3
    tried replacing ~/ with the exact path? Commented Jul 5, 2012 at 8:11
  • when execing from php always use the full-path as Tobas suggests! Also 'recommends' this in the docs if it's not a native command. Commented Jul 5, 2012 at 8:21

2 Answers 2

1

Sigh... another non-self-helping user...

http://php.net/manual/en/function.exec.php

Take note on PERMISSIONS.

Sign up to request clarification or add additional context in comments.

4 Comments

The permissions seems to only talk about running off an MS server, I am on a linux box. Strange as it was working before.
you will need to make sure also that apache has the correct permissions usign chmod/chown etc etc as required to allow execution
I actually think it was because the original c was compiled server-side. Do you have any make files Brian that could be run on a linux machine?
Brian all the permissions are fine as the original worked as I have a feeling my old engineer compiled it on the server. I has been working until today when I had to update my GNU (via Xcode) as I updated to Lion on my Mac.
1

A probably incomplete list would be: exec(), system(), shell_exec(), backticks, popen(), proc_open(), passthru().

EDIT:

Check this warning:

With safe mode enabled, the command string is escaped with escapeshellcmd(). Thus, echo y | echo x becomes echo y \| echo x.

From function.popen.php

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.