Search the Community
Showing results for tags 'aspell'.
-
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.html https://www.autoitscript.com/forum/topic/120575-createprocess-with-stdio-solved/ https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx I wrote this script: #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 ;==>_Run but I am only able to read the 1st introduction line of the Aspell.exe: 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.
-
- aspell
- createprocess
-
(and 1 more)
Tagged with: