dsgsdg206050 2017-02-02 04:48
浏览 188
已采纳

无法在shell_exec函数中传递参数

I am pretty new to using the shell commands.I am doing a debugger application in php.I need to check the result of the .exe files to check whether the logic of the code is right.So I tried a test program .

The C program is

include

#define MAX 128
int main(char c)
{
const int max=127;
char array[max]; // char array[10];
char string[MAX];
scanf("%c",&c);
array[0] = string[0] = c;
printf("%c %c
", array[0], string[0]);
return 0;
}

This is compiled as se.exe

PHP CODE

<?php 
define('STDIN',fopen("php://stdin","r"));
$cor1=1;
$op=shell_exec("se.exe H");
echo($op);  
if($op=="H H")
$cor1+=1;
echo $cor1;
if($cor1>1)
{echo "PASSED";}
else
{echo "FAILED";}
?>

This is not echoing any values.

  • 写回答

2条回答 默认 最新

  • douweiluo0600 2017-02-02 16:10
    关注

    I think the argument is successfully being passed. The c code not using the argument. It is doing scanf to get user input and not really using the argument that is being passed. You need to change the c code to use the argument.

    int main(int argc, char *argv[]) { 
        /* ... 
        argv[0] will have the executable name as a char array (char *)
        argv[1] will have the first command line argument as a char array (char *)
        argv[1][0] will have the first character of the first parameter that you seem to be interested.
        ensure that you do proper null check or you will get core dump/application crash
        */ 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作