This is my PHP code for passing data to a C# exe file.
<?
shell_exec("p3.exe --tRyMe");
?>
What I want is, I'll post a string to p3.exe file, and that exe file prints "tRyme" string to the screen.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string a;
Console.Write("Please enter a string : ");
a = Console.ReadLine();
Console.WriteLine("You have entered: {0}", a);
Console.ReadKey();
}
}
}
And this is my C# code.
I've tried "--tRyMe", "-tRyMe", "tRyMe" etc. to do that but, this code prints only "Please enter a string" to the screen.
What I want is see the output like:
You have entered: tRyMe
Can you help me with doing that? Best wishes.
I can't discuss the PHP code, but in the c# side, you need to check the number of arguments passed to your program from the command line and if there is an argument, don't ask for input, but print the argument received
static void Main(string[] args)
{
string a;
if(args.Length == 0)
{
Console.Write("Please enter a string : ");
a = Console.ReadLine();
}
else
a = args[0];
Console.WriteLine("You have entered: {0}", a);
Console.ReadKey();
}
Without having tried it, does a pipe work?
<?php
shell_exec("echo tRyMe | p3.exe");
?>
you could only run an application and print the output but you can not interact with the application - Console.ReadLine() expects an input ... so you can't use it (affects also Console.ReadKey())
try this:
static void Main(string[] args)
{
string a;
if(args.Length == 0)
a = "No arg is given";
else
a = args[0];
Console.WriteLine("You have entered: {0}", a);
}