C# 用PHP将数据传递到可执行文件
这是我的PHP代码,用于将数据传递到C#exe文件C# 用PHP将数据传递到可执行文件,c#,php,C#,Php,这是我的PHP代码,用于将数据传递到C#exe文件 <? shell_exec("p3.exe --tRyMe"); ?> 这是我的C代码 我已经尝试过“-tRyMe”、“-tRyMe”、“tRyMe”等,但此代码只在屏幕上打印“请输入字符串” using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program
<?
shell_exec("p3.exe --tRyMe");
?>
这是我的C代码
我已经尝试过“-tRyMe”、“-tRyMe”、“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();
}
}
}
我想要的是看到如下输出:
您已输入:tRyMe
你能帮我做那件事吗?
致以最良好的祝愿。没有试过,管道管用吗
<?php
shell_exec("echo tRyMe | p3.exe");
?>
我不能讨论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();
}
您只能运行应用程序并打印输出,但无法与应用程序交互-控制台。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);
}
谢谢你的快速回答。我试着这样做了3个小时:(我认为你是新来的
C
;这在我看来是件好事。每个人都必须从某个地方开始!在你的代码中,你没有从字符串[]中读取任何内容args
。我不是C#
人,但从逻辑上讲,这是一个字符串数组,在从用户输入中读取a
之前,您需要先检查它。