我的问题很简单,但我似乎绝对不可能找到解决方案。
我有一个专用的游戏服务器 (JEDI ACADEMY JAMPDED),它是一个控制台应用程序。它不断写入一些信息,我想以某种方式处理数据。如果我可以用外部读取它的输出,那将很容易。
问题:它不写入标准输出,因此无法使用批处理文件进行管道传输,并且 popen 也不起作用。
所以我想做WINAPI。我能够创建进程,但仍然无法读取输出。
我试过这些:
和 MSDN 官方示例,但仍然没有。
这是 jampded.exe:
我从我的朋友那里得到了一个视觉基本代码,他从 Ingame 读取 ConsoleInput,所以我很确定,可以读取控制台:
片段:
Global hWnd = FindWindow_(#Null,"Jedi Knight Academy MP Console") ;console window
Global hWnd2 = FindWindow_(#Null,"Jedi Knight®: Jedi Academy (MP)") ;actual game window
Global inputhWnd = FindWindowEx_(hwnd,0,"edit",0) ;the one to send stuff to
Global consolehWnd = FindWindowEx_(hwnd,inputhWnd,"edit",0) ;the one to read the console from
Procedure checkConsole()
Protected wholetext.s, oldtext.s,text.s, checkname.s
Repeat
wholetext = getText()
If wholetext
text = StringField(wholetext,CountString(wholetext,#CRLF$),#CRLF$)
If oldtext <> text
oldtext = text
analyseConsole(@text)
EndIf
EndIf
Delay(20)
writePreferences()
Until quit
EndProcedure
Procedure.s getText()
Protected wholetext.s
If hWnd And hWnd2
If Not inputhWnd Or Not consolehWnd
inputhWnd = FindWindowEx_(hWnd,0,"edit",0)
consolehWnd = FindWindowEx_(hWnd,inputhWnd,"edit",0)
EndIf
length = SendMessage_(consolehWnd, #WM_GETTEXTLENGTH, 0, 0)
wholetext = Space(length)
SendMessage_(consolehWnd,#WM_GETTEXT,length + SizeOf(Character),@wholetext)
ProcedureReturn wholetext
Else
If FindWindow_(#Null,"Jedi Knight Academy MP Console")
hWnd = FindWindow_(#Null,"Jedi Knight Academy MP Console")
hWnd2 = FindWindow_(#Null,"Jedi Knight®: Jedi Academy (MP)")
inputhWnd = FindWindowEx_(hwnd,0,"edit",0)
consolehWnd = FindWindowEx_(hwnd,inputhWnd,"edit",0)
EndIf
ProcedureReturn ""
EndIf
If @wholetext > 0
FreeMemory(@wholetext)
EndIf
EndProcedure
也许这也可以帮助我和其他人:)