dongyunshan4066 2017-03-21 21:38
浏览 57

如何从我的php脚本向我的可执行文件发送参数?

I am building a website using php. I need to send a variable to a command line executable from the php site, run the executable, and then read the response.

I believe I am not sending the argument to the executable correctly.

My php code:

<?php
$a=escapeshellarg('6');
//set $c [lindex $argv 0];
$answer = shell_exec("D:/WebPages/Test/PHP_Test.exe $a");
echo $answer;
?>

My c# executable code

using System;

namespace PHP_Test
{
    class Hello
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please enter a numeric argument.");
            }
            else
            {
                Console.WriteLine("Hello World!");

            }
        }
    }
}

As you can see, my executable is currently just set up to provide a response based on whether an argument was provided or not. When I don't send an argument from php, I get the correct response ("Please enter a numeric argument."). However, whenever I try to provide an argument, I am not getting any feedback at all, leading me to believe I am doing it incorrectly.

Any help is appreciated thank you.

  • 写回答

2条回答 默认 最新

  • drxd54816 2017-03-21 21:43
    关注

    With single quotes variable are not substituted with its values, you should use double quotes:

    Edit: and add 2>&1 at the end of the command to get also the STDERR

    $answer = shell_exec("D:\WebPages\PHP_Test.exe $a 2>&1");
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图