如何调用 c++ 来自 Perl 或 PHP 的二进制文件(在 Linux 上使用 Apache 的 CGI-BIN)?

发布于 2024-07-08 13:50:11 字数 216 浏览 7 评论 0原文

我有一个用 C++ 编写的网站 cgi-bin 程序。

不幸的是,我朋友网站的网站提供商只允许 Perl 或 PHP cgi-bin 脚本。

有没有一种简单的方法来简单地拥有一个非常小的 Perl 或 PHP 包装器,只调用 c++ 编译的二进制文件?

C++ 程序是否仍然能够从标准输入读取 POST 命令,或者必须由 Perl 或 PHP 读取然后转发。

I have a website cgi-bin program that is written in c++.

Unfortunately the website provider for my friend's site only allows Perl or PHP cgi-bin scripts.

Is there an easy way to simply have a very small Perl or PHP wrapper that just calls the c++ compiled binary?

Would the c++ program still be able to read from stdin for POST commands or would it have to be read by the Perl or PHP and then forwarded.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

待"谢繁草 2024-07-15 13:50:11

您可以使用 Perl 的反引号或“系统”命令来运行 shell 命令。 另外,perl 有很多“内联”类,允许您用其他语言编写代码以在 perl 中调用,其中包括一个用于 C++。 如果您找不到有效的东西,也许您可​​以使用该包制作自己的包装器。

You can use Perl's backticks or "system" commands to run shell commands. Also, perl has a lot of "Inline" classes that allow you to write code in other languages to be called in perl, including one for C++. If you can't find something that works, maybe you can make your own wrapper using that package.

秋意浓 2024-07-15 13:50:11

您可以使用 PHP 的 system() 函数来执行 shell 命令,您可以使用该命令来启动另一个程序。 该程序的 STDOUT 然后将转到与 php 的 stdout 相同的位置(到 HTTP 连接)。 您可能需要做一些乱七八糟的事情才能让标准输入从 get/post/etc 中读取。

但很可能网站提供商已禁用您以这种方式执行程序的能力。 这可能是一个安全风险,如果他们专门只允许 php 和 perl,那么他们可能会专门禁用尽可能多的运行非 php/perl 的方法。 所以,简短的回答是你可能不走运。

You can use PHP's system() function to execute a shell command, which you could use to launch another program. The STDOUT of that program would then go to the same place as php's stdout (to the HTTP connection). You might have to do some messing around to get stdin to read from get/post/etc.

But most likely the website provider has disabled the ability of you to execute programs in this way. It can be a security risk, and if they specifically only allow php and perl, then they would probably specifically disable as many methods of running non-php/perl as they could. So, short answer is you're probably out of luck.

终难遇 2024-07-15 13:50:11

请参阅我的 Awstats Wrapper 博客文章,了解一些 PHP 代码解决了我的问题。 我的方法是构造一个命令行,该命令行具有从 CGI 查询参数设置的正确环境变量,然后对结果输出进行替换,以便任何返回到 CGI 的链接都将转到我的包装器脚本。 我还取消了 CGI 的标头输出,因为 PHP 提供了自己的标头。

See my Awstats Wrapper blog post for some PHP code that solved my problem. My approach was to construct a command line that has the right environment variables set from the CGI query params and then do substitutions on the resulting output so that any links back to the CGI would go to my wrapper script instead. I also nuked the headers output from the CGI since PHP provides its own headers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文