开发者

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. I want to write any command (e.g. “q” which terminates the underlying process) but it seems that my code is not writing the input of the console application. Here is the code:

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

I also tried using

proc开发者_C百科essStreamWriter.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.

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. Console apps can still use all the normal Win32 APIs, including the GUI ones, so they can still provide a GUI-style interface.

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. 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.

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.

Sorry for the C syntax - I hope the translation to C# is simple and direct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜