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.