메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

Autoit named pipe 사용예제

데브카페
Devcafe (토론 | 기여)님의 2024년 11월 5일 (화) 00:42 판 (새 문서: == Autoit named pipe 사용예제 == * 명령창에서 실행하는 명령 출력해 주는 함수 * Named Pipe를 사용하는 API를 이용해서 명령프롬프트의 출력 내용을 읽기 <source lang=autoit> #include <NamedPipes.au3> #include <WinAPI.au3> #include <Constants.au3> Func StdOut($sCmd, $sWorkingDir = "", $state = @SW_HIDE) Local $iBytes, $sData, $hReadPipe, $hWritePipe, $tBuffer, $tProcess, $tSecurity, $tStartup Local $STILL_ACTIVE = 0x103 Local C...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

Autoit named pipe 사용예제

  • 명령창에서 실행하는 명령 출력해 주는 함수
  • Named Pipe를 사용하는 API를 이용해서 명령프롬프트의 출력 내용을 읽기
#include <NamedPipes.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Func StdOut($sCmd, $sWorkingDir = "", $state = @SW_HIDE)
   Local $iBytes, $sData, $hReadPipe, $hWritePipe, $tBuffer, $tProcess, $tSecurity, $tStartup
   Local $STILL_ACTIVE = 0x103
   Local Const $STARTF_USESHOWWINDOW = 0x1
   Local Const $STARTF_USESTDHANDLES = 0x100

   $tSecurity = DllStructCreate($tagSECURITY_ATTRIBUTES)
   DllStructSetData($tSecurity, "Length", DllStructGetSize($tSecurity))
   DllStructSetData($tSecurity, "InheritHandle", True)

   _NamedPipes_CreatePipe($hReadPipe, $hWritePipe, $tSecurity)

   $tProcess = DllStructCreate($tagPROCESS_INFORMATION)
   $tStartup = DllStructCreate($tagSTARTUPINFO)
   DllStructSetData($tStartup, "Size", DllStructGetSize($tStartup))
   DllStructSetData($tStartup, "Flags", BitOR($STARTF_USESTDHANDLES, $STARTF_USESHOWWINDOW))
   DllStructSetData($tStartup, "StdOutput", $hWritePipe)
   DllStructSetData($tStartup, "StdError", $hWritePipe)
   DllStructSetData($tStartup, "ShowWindow", $state)
   _WinAPI_CreateProcess("", $sCmd, 0, 0, True, 0, 0, $sWorkingDir, DllStructGetPtr($tStartup), DllStructGetPtr($tProcess))
   Local $handle = DllStructGetData($tProcess, "hProcess")

   _WinAPI_CloseHandle(DllStructGetData($tProcess, "hThread"))
   Local $kernel = DllOpen("kernel32.dll")

   _WinAPI_CloseHandle($handle)
   _WinAPI_CloseHandle($hWritePipe)

   $tBuffer = DllStructCreate("char Text[4096]")
   While 1
      _WinAPI_ReadFile($hReadPipe, DllStructGetPtr($tBuffer), 4096, $iBytes)
      If $iBytes = 0 Then ExitLoop
      $sData &= StringLeft(DllStructGetData($tBuffer, "Text"), $iBytes)
   WEnd
   _WinAPI_CloseHandle($hReadPipe)

   Return $sData
EndFunc

Comments