简体   繁体   English

PHP exec()错误输出

[英]PHP exec() wrong output

I am executing an AJAX request using jQuery as such: 我正在使用jQuery这样执行AJAX请求:

$.get({
          url: 'run_program.php',
          data: 'action=run&number=' + $('#number').val(),
          success: function (j) {
            alert(j);
          }

runprogram.php is as such: runprogram.php是这样的:

<?php
if(isset($_GET['action']) && !empty($_GET['action'])) {
    run($_GET['number']);
}

function run($number) {
    echo shell_exec('program.exe $number');
}
?>

The response I get from the server is always 0. I am running this locally by the way, so there are no security problems. 我从服务器获得的响应始终为0。顺便说一下,我在本地运行此响应,因此没有安全问题。 The program is simply coded to square the number passed in as input. 只需将程序编码为输入的数字平方即可。 It works perfectly fine in cmd. 它在cmd中工作得很好。 When I echo $number, it correctly gives the value that I passed in using jQuery. 当我回显$ number时,它正确地给出了我使用jQuery传递的值。 What is the problem in my code? 我的代码有什么问题?

The problem would be your line 问题是你的线

echo shell_exec('program.exe $number'); 

in that this will actually call program.exe with "$number" as text as a value. 因为它实际上将以“ $ number”作为文本值来调用program.exe。 You need to use double quotes eg 您需要使用双引号,例如

echo shell_exec("program.exe $number"); 

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

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