简体   繁体   English

该应用程序包括一个可执行文件,该文件要求用户在命令提示符下输入。 想要自动化,以便没有cmd提示打开

[英]Application to include an executable which ask user input in command prompt. Want to automate so that no cmd prompt opens

I have a WPF application in which I want to integrate a module. 我有一个要集成模块的WPF应用程序。 the other module is an executable which when clicked prompts for user response. 另一个模块是可执行文件,单击该文件时提示用户响应。 Based on the user response it will process or exit: 根据用户的响应,它将处理或退出:

for eg: 例如:

C:\>Abc.exe press enter
> command1 
//Executing command1  -- command1 will create a log file
>exit
//Exits the Abc.exe process
C:\>

So I want to integrate this part into my WPf application. 因此,我想将此部分集成到我的WPf应用程序中。 When a button is in WPF application, above steps are executed automatically. 在WPF应用程序中有按钮时,以上步骤将自动执行。

i have no idea on how to execute shell prompt which required user input. 我不知道如何执行需要用户输入的shell提示。

Process process1 = new Process();
            process1.StartInfo.FileName = "C:\\abc.exe";
            process1.StartInfo.RedirectStandardInput = true;
            process1.StartInfo.RedirectStandardError = true;
            process1.StartInfo.UseShellExecute = false;
            process1.StartInfo.CreateNoWindow = false;
            process1.Start();
            StreamWriter inputWriter = process1.StandardInput;
            process1.StandardInput.WriteLine("command1");
            process1.StandardInput.Flush();
            System.Threading.Thread.Sleep(1500);
            process1.StandardInput.WriteLine("exit");
            process1.StandardInput.Flush();

            process1.Kill();

But it opens up the abc.exe in console, but does not execute the commands ie command1 and exit. 但是它将在控制台中打开abc.exe,但是不执行命令command1并退出。

I don't know how to do it in WPF, but in Win32 you would use CreateProcess() with redirected input/output so you can send your own input data and read any output data as needed. 我不知道如何在WPF中执行此操作,但是在Win32中,您可以将CreateProcess()与重定向的输入/输出一起使用,以便可以发送自己的输入数据并根据需要读取任何输出数据。

How to spawn console processes with redirected standard handles 如何使用重定向的标准句柄生成控制台进程

Creating a Child Process with Redirected Input and Output 创建具有重定向输入和输出的子进程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM