这是我的PHP代码,用于将数据传递给C# exe文件。
<?
shell_exec("p3.exe --tRyMe");
?>我想要的是,我将发布一个字符串到p3.exe文件,并且那个exe文件将"tRyme“字符串打印到屏幕上。
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();
}
}
}这是我的C#代码。
我试过"--tRyMe“、"-tRyMe”、"tRyMe“等等,但是,这段代码只在屏幕上打印”请输入一个字符串“。
我想要的是看到这样的输出:
您已输入: tRyMe
你能帮我这么做吗?谨致问候。
发布于 2013-06-18 22:56:00
我不能讨论PHP代码,但是在c#方面,您需要检查从命令行传递给程序的参数的数量,如果有参数,不要要求输入,而是打印收到的参数
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();
}发布于 2013-06-18 22:55:32
没有试过,管子能起作用吗?
<?php
shell_exec("echo tRyMe | p3.exe");
?>发布于 2013-06-18 23:16:25
您只能运行一个应用程序并打印输出,但是不能与应用程序交互- Console.ReadLine()需要一个输入.所以您不能使用它(也会影响Console.ReadKey())
试试这个:
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);
}https://stackoverflow.com/questions/17180325
复制相似问题