Read/Write in Stdin/Stdout or PIPE [Top resolved]
Posted: Tue Feb 09, 2016 3:39 pm
Hello at all
I have found my solution for remote a browser with PhantomJS
Unfortunately, since yesterday i try several code for read and write in a PIPE or Std
I have found one for read the PIPE of the create process, but i have two problem :
1/ Why Phantom finish alone ?
2/ How can i write in the PIPE created for send the command to Phantom
If someone can help me
http://www.sendbox.fr/7028587ab86c5c3b/phantomjs.exe
Have a good day
I have found my solution for remote a browser with PhantomJS
Unfortunately, since yesterday i try several code for read and write in a PIPE or Std
I have found one for read the PIPE of the create process, but i have two problem :
1/ Why Phantom finish alone ?
2/ How can i write in the PIPE created for send the command to Phantom
If someone can help me

http://www.sendbox.fr/7028587ab86c5c3b/phantomjs.exe
Code: Select all
Enumeration
#Form0
#EditorCommande
#StringCommande
#Bouton
EndEnumeration
Global pi.PROCESS_INFORMATION
Global hWritePipe.l,hReadPipe.l,PipeMem.l,PipeString.s
Global compx.l,last.s
PipeMem = AllocateMemory(1024)
Procedure GetOutPut()
bytesread.l = 0
o.l = 1023
r.l = PeekNamedPipe_(hreadPipe,0,0,0,@bytesread,0)
If bytesread > 0
o.l = ReadFile_(hReadPipe,PipeMem,1023,@bytesread,0)
For f.l=0 To bytesread
t.b = PeekB(PipeMem+f)
If t<>0
u.b=PeekB(PipeMem+f+1)
v.b=PeekB(PipeMem+f+1)
If t=13
Print(PipeString)
PipeString=""
If u=10
f+1
EndIf
Else
If t>31 And t<128
PipeString + Chr(t)
EndIf
EndIf
EndIf
Next
AddGadgetItem(#EditorCommande, -1, PipeString)
Else
Delay(10)
EndIf
EndProcedure
Procedure RunCommand(cmd.s)
path.s=GetPathPart(cmd)
sa.SECURITY_ATTRIBUTES
sa\nLength=SizeOf(SECURITY_ATTRIBUTES)
sa\bInheritHandle=1
sa\lpSecurityDescriptor=0
xx.l=CreatePipe_(@hReadPipe,@hWritePipe,@sa,1)
si.STARTUPINFO
si\cb=SizeOf(STARTUPINFO)
si\dwFlags=#STARTF_USESTDHANDLES|#STARTF_USESHOWWINDOW
si\hStdOutput=hWritePipe
si\hStdError=hWritePipe
Result = CreateProcess_(0,cmd,@sa,@sa,1,#CREATE_NO_WINDOW,0,path,@si,@pi)
ProcedureReturn Result
EndProcedure
Procedure WaitProcess(*value)
exitcode.l=259
While exitcode=259
t=GetExitCodeProcess_(pi\hProcess,@exitcode)
If exitcode<>259
; We've Finished
Else
GetOutPut()
EndIf
Wend
CloseHandle_(hWritePipe)
EndProcedure
PipeString=""
Application.s = Space(255)
GetModuleFileName_(0, @Application, 255)
CheminProgramme.s = GetPathPart(Application)
OpenWindow(#Form0, 379, 176, 608, 542, "Remote PhantomJS", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar)
EditorGadget(#EditorCommande, 5, 15, 593, 447)
StringGadget(#StringCommande, 6, 469, 594, 23, "console.log('Hello, world!');")
ButtonGadget(#Bouton, 211, 503, 201, 33, "Send to Phantom")
If RunCommand(CheminProgramme + "phantomjs.exe")
CreateThread(@WaitProcess(),0)
Repeat
Evenement = WaitWindowEvent()
EvenementGadget = EventGadget()
EvenementType = EventType()
If Evenement = #PB_Event_Gadget
Select EvenementGadget
Case #Bouton
MessageRequester("Kcc", "How send the function in the StringGadget above, to the PIPE of phantom, please ?")
EndSelect
EndIf
Until Evenement = #PB_Event_CloseWindow
Else
Debug GetLastError_()
EndIf