0

I created shared library client.so. When I execute it main() function get executed which reads string from user and calls function ch=foo(buffer);.

Main.cpp is here:

#include<stdio.h>
#include "foo.h"

    int main()
    {
        char buffer[1024];
        char *ch;
        printf("Client : \n");
        printf("Enter sentence to send to the server (press enter)\n");
        fgets(buffer, 1024, stdin);
        ch=foo(buffer);

        return 0;
    }

Using exec function we can execute c program. But in php script if I do it for this I won't have option to read string from user.

I want that user can enter the string in browser itself and I pass that string to main function(probably using argv,argc- but I dont know how to do this). Then main function should proceed as usual calling foo(buffer) and so on.

foo(buffer) will return array which is stored in char* ch I want to receive in php script.

I have two option: 1] Reading string in text box from user and passing it to shared library file which has main() function. Which get executed and return "ch" in php script 2] Executing shared library file (as we do in terminal ./client) and giving string input at run time and getting entire program run. But I dont know this is possible or not. #include #include "foo.h"

    int main()
    {
        char buffer[1024];
        char *ch;
        printf("Client : \n");
        printf("Enter sentence to send to the server (press enter)\n");
        fgets(buffer, 1024, stdin);
        ch=foo(buffer);

        return 0;
    }

can anyone give me some suggestion for how this could be achieved!

4

2 回答 2

0

设置权限后按以下方式执行即可解决问题:

$a=exec('/home/technoworld/Videos/LinSocket/client "critic good"'); 

./client没有必要像我犯错一样给予!

client 是我想要执行的可执行文件,“critic good”是要传递的参数!

于 2013-07-08T06:50:44.883 回答
0

你不能这么简单!

  1. 你必须决定,如果你真的想“执行”搞砸你的网络服务器
  2. 您必须将外部帮助工具编码为“非阻塞”应用程序,这意味着:没有 CLI 输入内容。如果您将参数/参数字符串直接“输入”和“输出”到“非阻塞”应用程序,则可以做到这一点。
  3. 您必须使用正确的权限保护网络服务器和包装工具。
  4. 你必须实现一个超时(或者你有很多僵尸pid)
  5. 您必须对您的应用程序“线程”安全进行编码(网络服务器必须启动应用程序的多个实例,这为每个请求(来自登录用户)只生成一个会话。
  6. 您必须测试有关志愿者的应用程序(缓冲区溢出,,,,)

如果您朝着正确的方向前进,您可以编写一个专门用于您的网络服务器 (apache) 的应用程序。这意味着:

  1. 在没有 UB 的情况下编写您的应用程序。
  2. 更改您的网络服务器(apache)配置:添加目录证券,添加应用程序处理程序,它可以处理每个 .extension 的文件,或与 CGI 接口一起使用。
  3. 这意味着,您拥有一个稳定、快速运行的系统,并且拥有与家用电脑一样多的内存。

换句话说:您不应该在生产系统的开发阶段使用您的应用程序。

于 2021-09-09T08:53:09.083 回答