【发布时间】:2016-05-18 07:00:29
【问题描述】:
我构建了一个控制台应用程序,它会提示输入用户名和密码
我有一个单击按钮的 Web 应用程序,一旦用户键入用户名和密码,我需要调用控制台 exe 来弹出用户名和密码,我需要获取要传递给我的 Web 应用程序的值
string filePath = @"D:\\ConsoleApplication\\ConsoleApplication\\ConsoleApplication\\bin\Debug\\ConsoleApplication.exe";
ProcessStartInfo info = new ProcessStartInfo(filePath, "");
Process p = Process.Start(info);
p.StartInfo.UseShellExecute = false; //don't use the shell to execute the cmd file
p.StartInfo.RedirectStandardOutput = true; //redirect the standard output
p.StartInfo.RedirectStandardError = true; //redirect standard errors
p.StartInfo.CreateNoWindow = true; //don't create a new window
p.Start(); //start the program
StreamReader sr = p.StandardOutput; //read the programs output
string output = sr.ReadToEnd(); //put output into list box
p.Close();
p.WaitForExit();
控制台应用代码:
public class Program
{
static void Main()
{
System.Console.WriteLine("Please enter User Name");
var userName = Console.ReadLine();
System.Console.WriteLine("Please enter Password");
var password = Console.ReadLine();
}
}
我需要获取keyin用户名和密码值,我需要返回网页
我尝试使用上面的代码从标准输出中获取值,但值是空的
谁能帮帮我..
【问题讨论】:
-
在你的 main() 调用 Process.Start("IEXPLORE.EXE", "-nomerge youresite.com?username=Kapil&password=Kapil"); 它将打开一个带有给定 URL 和查询字符串的 IE。
-
我需要获取用户键入的动态值。
-
是的,只需将硬编码的 Kapil 分别替换为用户名变量和密码变量即可。
-
如果我这样做,我要求在类库 proj 中运行控制台并且无法获取查询字符串。任何其他解决方案。
标签: c#-4.0 web-applications console console-application console.log