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

Autoit named pipe 사용예제: 두 판 사이의 차이

데브카페
새 문서: == 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...
 
잔글 개발노트 양식 일괄 적용
 
1번째 줄: 1번째 줄:
{{개발노트
|요약=명령창에서 실행하는 명령 출력해 주는 함수
|핵심=
|분야=Autoit
|작성일=2024-11-04
}}
== Autoit named pipe 사용예제 ==
== Autoit named pipe 사용예제 ==
* 명령창에서 실행하는 명령 출력해 주는 함수
* 명령창에서 실행하는 명령 출력해 주는 함수

2026년 11월 12일 (목) 12:45 기준 최신판

DEVCAFE NOTE
Autoit
명령창에서 실행하는 명령 출력해 주는 함수
KEY POINTS · 핵심 정리
작성일2024년 11월 4일

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