dsag14654 2016-06-21 18:06
浏览 55

从PHP执行C程序

I am executing a C program i.e. '.exe' that is an executable file from PHP.

I have an interface with an HTML which calls a PHP file whenever I click a button.

On PHP, it calls up a shell script. So on PHP, I use the following:

echo shell_exec('sh auto_script.sh');

The shell file executes the program .exe as follows:

./import -file.txt

where import is my executable C program .exe and file.txt is an input which I am hard coding as of now.

Executable file 'import' is stored in the same direcotry as php file called.

When I execute the shell script on a terminal, it executes properly with the necessary output.

But when I try to execute it from PHP it doesnt work. I have given full permissions to file as of now.

  • 写回答

1条回答 默认 最新

  • duanlie7447 2016-06-21 18:51
    关注

    A quick check on the [ shell_exec ] manpage says shell_exec has the following definition :

    string shell_exec ( string $cmd )

    which means that the argument should be a string, which indeed means it should be inside quotes. BTW, you don't need a mediator script here anyways, So do :

    echo shell_exec('./import "-file.txt"'); //Using relative paths
    

    Having said that placing the binary in the scripts folder is a bad idea, but I hope above helps you to get you going.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数