Write to a pipe not working?

Just starting out? Need help? Post your questions and find answers here.
Johan_Haegg
User
User
Posts: 60
Joined: Wed Apr 30, 2003 2:25 pm
Location: Västerås
Contact:

Write to a pipe not working?

Post by Johan_Haegg »

Well, not at the same time as networking...

Any idea?

Code: Select all

; Redirect Outputs into Memory
; coded by Siegfried Rings march 2002
; redirected the pipes
; Modified by Johan Hägg March 2004
; BUG: Wont work with network =/
;
;see <http://support.microsoft.com/default.aspx?scid=kb;EN-US;q173085>
;
InitNetwork()
CreateNetworkServer(23)
OpenConsole()
PrintN("Started")
Repeat
Delay(10)

Until NetworkServerEvent() = 1
cid = NetworkClientID()
mCommand.s="cmd"

proc.PROCESS_INFORMATION ;Process info filled by CreateProcessA
ret.l ;long variable For get the Return value of the
start.STARTUPINFO ;StartUp Info passed To the CreateProceeeA
sa.SECURITY_ATTRIBUTES ;Security Attributes passeed To the
hReadPipe1.l
hReadPipe2.l
hReadPipe3.l
hWritePipe1.l
hWritePipe2.l
hWritePipe3.l

lngBytesread.l ;Amount of byte Read from the Read Pipe handle

;Consts For functions
#NORMAL_PRIORITY_CLASS = $20
#STARTF_USESTDHANDLES = $100
#STARTF_USESHOWWINDOW = $1

;Create the Pipe
sa\nLength =SizeOf(SECURITY_ATTRIBUTES) ;Len(sa)
sa\bInheritHandle = 1
sa\lpSecurityDescriptor = 0
ret = CreatePipe_(@hReadPipe1, @hWritePipe1, @sa, 0)
ret = CreatePipe_(@hReadPipe2, @hWritePipe2, @sa, 0)
ret = CreatePipe_(@hReadPipe3, @hWritePipe3, @sa, 0)

start\cb = SizeOf(STARTUPINFO)
start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES

start\hStdOutput = hWritePipe1
start\hStdError = hWritePipe2
start\hStdInput = hWritePipe3
;start\hStdInput = hReadPipe3 ;Should be

ret = CreateProcess_(0, mCommand, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc)

ret = CloseHandle_(hWritePipe1) ;Not

mOutputs.s = ""
buff = AllocateMemory(#1, 255)
quit = 0

While quit = 0
  get = recv_(cid, buff, 255, 0)
  If get > 0
;    If get > 1
;      If PeekW(buff + get - 2) = 2573
;        Debug "CRLF"
;        PokeB(buff + get - 2, 13)
;        get - 1
;      EndIf
;    EndIf
    WriteFile_(hWritePipe3, buff, get, @lngBytesread, 0)
    Print(PeekS(buff, get))
    If lngBytesread <> get
      Debug "Dropped " + Str(get - lngBytesread) + " byte"
    EndIf
  Else
    Delay(100)
  EndIf
  ReadFile_(hReadPipe1, buff, 255, @lngBytesread, 0)
  If lngBytesread > 0
    send = send_(cid, buff, lngBytesread, 0)
    Print(PeekS(buff, send))
  EndIf
Wend

;Close the opened handles
ret = CloseHandle_(proc\hProcess)
ret = CloseHandle_(proc\hThread)
ret = CloseHandle_(hReadPipe1)
ret = CloseHandle_(hReadPipe2)
ret = CloseHandle_(hReadPipe3)
ret = CloseHandle_(hWritePipe2)
ret = CloseHandle_(hWritePipe3)