简体   繁体   English

从php运行C程序

[英]Running a C program from php

I have a C program I have compiled to a exe called crunch. 我有一个C程序,我编译成一个名为crunch的exe程序。

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: 在我的PHP中,我一直在执行它:

$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. $ code最初是一个URL,它是一个URL。 It has been returning a hash but not any more. 它已经返回哈希,但不再是。

I have recompiled the C a few times. 我已经重新编译了C几次。 Just don't get it, I have tried php exec() , passthru(). 只是不明白,我尝试过php exec(),passthru()。

FIXED: 固定:

The issue was the difference between my Mac Unix distros and the linux server. 问题是我的Mac Unix发行版和linux服务器之间的区别。 The fix was to log into my server and compile the .c file there. 修复是登录我的服务器并在那里编译.c文件。

Bobs your Uncle, works again. Bobs你的叔叔,再次工作。

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 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() . 一个可能不完整的列表是: exec()system()shell_exec()backtickspopen()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 来自function.popen.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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