简体   繁体   English

无法从 win32 应用程序写入控制台应用程序

[英]can't write in console application from win32 application

I'm trying to control a console application from C# win32 application, the console application (oclHashcat-lite32) is unknown for me, I don't have the code, until now I'm not capable to write in the console application.我正在尝试从 C# win32 应用程序控制控制台应用程序,控制台应用程序(oclHashcat-lite32)对我来说是未知的,我没有代码,直到现在我无法在控制台应用程序中编写。 I want to write any command (eg “q” which terminates the underlying process) but it seems that my code is not writing the input of the console application.我想编写任何命令(例如终止底层进程的“q”),但我的代码似乎没有编写控制台应用程序的输入。 Here is the code:这是代码:

StreamWriter processStreamWriter = OCLProcess.StandardInput;
processStreamWriter.Write("q"); 
processStreamWriter.Close(); 

I also tried using我也尝试过使用

processStreamWriter.WriteLine("q");

Instead of代替

 processStreamWriter.Write("q");

But it did not work.但它没有用。 Any suggestion?有什么建议吗?

IIRC, if you build a win32 app as a GUI app, the standard streams aren't linked up to anything - StandardInput will never give you any input, and StandardOutput will throw the output away. IIRC,如果您将 win32 应用程序构建为 GUI 应用程序,则标准流不会链接到任何东西 - StandardInput 永远不会给您任何输入,StandardOutput 会将 output 扔掉。

The quick fix for that (in C - so take with a pinch of salt) was, I think, to build your GUI app as a console app using the option in the project file.我认为,对此的快速修复(在 C 中 - 所以需要一点盐)是使用项目文件中的选项将您的 GUI 应用程序构建为控制台应用程序。 Console apps can still use all the normal Win32 APIs, including the GUI ones, so they can still provide a GUI-style interface.控制台应用程序仍然可以使用所有正常的 Win32 API,包括 GUI 的 API,因此它们仍然可以提供 GUI 样式的界面。

However, unless you really want to I/O to the standard input/output of your GUI app (not the same as the standard input/etc for your child console app), you don't need it.但是,除非您真的想要 I/O 到您的 GUI 应用程序的标准输入/输出(与您的子控制台应用程序的标准输入/等不同),否则您不需要它。 There is a way to start a process which provide stream handles for the standard input, standard output and standard error streams for that newly started process, so you can send output that that process will recieve as standard input etc.有一种方法可以启动一个进程,它为标准输入、标准 output 和标准错误流提供 stream 句柄,并为新启动的进程提供标准错误流,因此您可以发送 Z78E6221F6393D1356681DB398F14CE6ZD 作为标准输入等。

http://msdn.microsoft.com/en-us/library/ms682499%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/ms682499%28v=vs.85%29.aspx

Incidentally, that link also shows the GetStdHandle(STD_OUTPUT_HANDLE) and similar calls being used.顺便说一句,该链接还显示了GetStdHandle(STD_OUTPUT_HANDLE)和正在使用的类似调用。

Sorry for the C syntax - I hope the translation to C# is simple and direct.抱歉 C 语法 - 我希望 C# 的翻译简单直接。

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

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