简体   繁体   中英

Running a C program from php

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!

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

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

Take note on PERMISSIONS.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM