Digisoul Posted June 17, 2015 Share Posted June 17, 2015 (edited) Hello,I am trying to create a Spell Checker with help of Aspell.exe, my intention is to communicate with Aspell.exe through _NamedPipes_CreatePipe , after reading the following articles & discussions:http://aspell.net/man-html/Through-A-Pipe.htmlhttps://www.autoitscript.com/forum/topic/120575-createprocess-with-stdio-solved/https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspxI wrote this script:expandcollapse popup#include <AutoItConstants.au3> #include <WinAPI.au3> #include <NamedPipes.au3> Global $hOutRead, $hOutWrite, $hInRead, $hInWrite Global $hSTD_OUT_ReadPipe, $hSTD_OUT_WritePipe Global $hSTD_IN_ReadPipe, $hSTD_IN_WritePipe $iPID = _Run("C:\Program Files (x86)\Aspell\bin\aspell.exe", " -a", "C:\Program Files (x86)\Aspell\bin") ConsoleWrite("pid:" & $iPID & @LF) ;read 1st msg _ReadMsg() ; try to check spell Local $iData,$nBytes,$tBuffer $iData = "Thq Quick Brown Fox Jumps ovzr tha lezy dog." $tBuffer = DllStructCreate("byte["&StringLen($iData)&"]") $res = _WinAPI_WriteFile($hSTD_IN_WritePipe, DllStructGetPtr($tBuffer), StringLen($iData), $nBytes) ConsoleWrite(">WriteResult:"&$res&":"&$nBytes&@LF) ; totally stuck _ReadMsg() _WinAPI_CloseHandle($hSTD_OUT_ReadPipe) Exit Func _ReadMsg() Local $tBuffer,$nBytes,$rData,$return While True ToolTip("i am stuck") $tBuffer = DllStructCreate("byte[4096]") $sOutput = _WinAPI_ReadFile($hSTD_OUT_ReadPipe, DllStructGetPtr($tBuffer), 4096, $nBytes,0) If $nBytes > 0 Then ; Exit the loop if the process closes or StdoutRead returns an error. $rData = BinaryToString(DllStructGetData($tBuffer, 1)) ConsoleWrite($rData) If StringInStr($rData, @LF) Then ConsoleWrite("msg complete" & @LF) ToolTip("") ExitLoop Else $return = $rData EndIf $tBuffer = 0 $nBytes = 0 Else ExitLoop EndIf WEnd ;-------------- Return $return EndFunc ;==>_ReadMsg Func _Run($location, $sCmd, $sWorkingDir = "", $state = @SW_SHOW) Local $tProcess, $tSecurity, $tStartup Local Const $STARTF_USESHOWWINDOW = 0x1 Local Const $STARTF_USESTDHANDLES = 0x100 ; Set up security attributes $tSecurity = DllStructCreate($tagSECURITY_ATTRIBUTES) DllStructSetData($tSecurity, "Length", DllStructGetSize($tSecurity)) DllStructSetData($tSecurity, "InheritHandle", True) DllStructSetData($tSecurity, "Descriptor", Null) ; Create a pipe for the child process's STDOUT ;************** _NamedPipes_CreatePipe($hSTD_OUT_ReadPipe, $hSTD_OUT_WritePipe,DllStructGetPtr($tSecurity)) _WinAPI_SetHandleInformation($hSTD_OUT_ReadPipe, 1, 0) ; dont inherte it ;~ _WinAPI_SetHandleInformation($hSTD_OUT_WritePipe, 1, 1) _NamedPipes_CreatePipe($hSTD_IN_ReadPipe, $hSTD_IN_WritePipe,DllStructGetPtr($tSecurity)) _WinAPI_SetHandleInformation($hSTD_IN_WritePipe, 1, 0) ; here is the problem ;~ _WinAPI_SetHandleInformation($hSTD_IN_ReadPipe, 1, 1) ;************** ; Create child process $tProcess = DllStructCreate($tagPROCESS_INFORMATION) $tStartup = DllStructCreate($tagSTARTUPINFO) DllStructSetData($tStartup, "Size", DllStructGetSize($tStartup)) DllStructSetData($tStartup, "Flags", BitOR($STARTF_USESTDHANDLES, $STARTF_USESHOWWINDOW)) DllStructSetData($tStartup, "StdOutput", $hSTD_OUT_WritePipe) DllStructSetData($tStartup, "StdError", $hSTD_OUT_WritePipe) DllStructSetData($tStartup, "StdInput", $hSTD_IN_ReadPipe) DllStructSetData($tStartup, "ShowWindow", $state) _WinAPI_CreateProcess($location, $sCmd, 0, 0, True, 0, 0, $sWorkingDir, DllStructGetPtr($tStartup), DllStructGetPtr($tProcess)) Return DllStructGetData($tProcess, "ProcessID") EndFunc ;==>_Runbut I am only able to read the 1st introduction line of the Aspell.exe: @(#) International Ispell Version 3.1.20 (but really Aspell 0.50.3) after that autoit process just stop responding, I am not sure where is the issue or what is the issue. Please help me here. Thanks in Advance. Edited June 17, 2015 by Digisoul Changed Title 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now