How can i run another PB application with Pipe ?
- skinkairewalker
- Enthusiast
- Posts: 636
- Joined: Fri Dec 04, 2015 9:26 pm
How can i run another PB application with Pipe ?
hi everyone !
i am not understand how can i speak with another application compiled with PB , using Pipe ...
how another application will "receive" message from pipe main application ? using input() ?
i am not understand how can i speak with another application compiled with PB , using Pipe ...
how another application will "receive" message from pipe main application ? using input() ?
Re: How can i run another PB application with Pipe ?
Try ReadConsoleData().
Here's an example:
Be warned, ReadConsoleData() blocks the program until some input is available! And there is no AvailableConsoleData() command to check first... So a thread might help.
Here's an example:
Code: Select all
IsSlave = Bool(ProgramParameter(0) = "-slave")
If OpenConsole()
If (IsSlave)
PrintN("Close this window to finish.")
PrintN("")
PrintN("Receiving strings...")
BSize = 1024
*Buffer = AllocateMemory(BSize)
While (#True)
If ReadConsoleData(*Buffer, BSize) ; This should be in a background thread...
In.s = PeekS(*Buffer, -1, #PB_UTF8)
PrintN(In)
EndIf
Delay(1)
Wend
FreeMemory(*Buffer)
EndIf
If (Not IsSlave)
PrintN("Starting slave program...")
PrintN("")
*Slave = RunProgram(ProgramFilename(), "-slave", GetCurrentDirectory(), #PB_Program_Open | #PB_Program_Write)
If (*Slave)
PrintN("Sending strings...")
While ProgramRunning(*Slave)
If WriteProgramString(*Slave, FormatDate("The time is %hh:%ii:%ss", Date()), #PB_UTF8)
PrintN("Sent!")
EndIf
Delay(1000)
Wend
PrintN("Done!")
CloseProgram(*Slave)
EndIf
EndIf
CloseConsole()
EndIf
- skinkairewalker
- Enthusiast
- Posts: 636
- Joined: Fri Dec 04, 2015 9:26 pm
Re: How can i run another PB application with Pipe ?
kenmo wrote:Try ReadConsoleData().
Here's an example:Be warned, ReadConsoleData() blocks the program until some input is available! And there is no AvailableConsoleData() command to check first... So a thread might help.Code: Select all
IsSlave = Bool(ProgramParameter(0) = "-slave") If OpenConsole() If (IsSlave) PrintN("Close this window to finish.") PrintN("") PrintN("Receiving strings...") BSize = 1024 *Buffer = AllocateMemory(BSize) While (#True) If ReadConsoleData(*Buffer, BSize) ; This should be in a background thread... In.s = PeekS(*Buffer, -1, #PB_UTF8) PrintN(In) EndIf Delay(1) Wend FreeMemory(*Buffer) EndIf If (Not IsSlave) PrintN("Starting slave program...") PrintN("") *Slave = RunProgram(ProgramFilename(), "-slave", GetCurrentDirectory(), #PB_Program_Open | #PB_Program_Write) If (*Slave) PrintN("Sending strings...") While ProgramRunning(*Slave) If WriteProgramString(*Slave, FormatDate("The time is %hh:%ii:%ss", Date()), #PB_UTF8) PrintN("Sent!") EndIf Delay(1000) Wend PrintN("Done!") CloseProgram(*Slave) EndIf EndIf CloseConsole() EndIf
thanks by you answer !
- skinkairewalker
- Enthusiast
- Posts: 636
- Joined: Fri Dec 04, 2015 9:26 pm
Re: How can i run another PB application with Pipe ?
when i add flag parameter in RunProgram "#PB_Program_Read" to receive message from *slave . happens it >
screenshot > http://prntscr.com/dh1sk1
slave dont receives message from master pipe .... why happens it ?
screenshot > http://prntscr.com/dh1sk1
slave dont receives message from master pipe .... why happens it ?
- skinkairewalker
- Enthusiast
- Posts: 636
- Joined: Fri Dec 04, 2015 9:26 pm
Re: How can i run another PB application with Pipe ?
well ...
im trying again receive message from slave , but i dont know how can i "send message" to máster ...
máster pipe code >
slave pipe code >
The result of WriteConsoleData and Printn it just "first" char of message ... > http://prntscr.com/dhazqs
im trying again receive message from slave , but i dont know how can i "send message" to máster ...
máster pipe code >
Code: Select all
Compiler = RunProgram("test.exe", "", GetCurrentDirectory(), #PB_Program_Open | #PB_Program_Read)
Output$ = ""
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Output$ + ReadProgramString(Compiler) + Chr(13)
EndIf
Wend
Output$ + Chr(13) + Chr(13)
Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))
Debug Output$
CloseProgram(Compiler) ; Close the connection to the program
EndIf
Code: Select all
*Buffer = AllocateMemory(2048)
OpenConsole()
;PrintN("HelloWorld") // Dont Works ...
PokeS (*Buffer,"Testing !")
WriteConsoleData(*Buffer,2048) ; // dont works
Re: How can i run another PB application with Pipe ?
I'm looking at this as well...
I can have the master spawn the slaves (runprogram with #PB_Program_Write|#PB_Program_Open|#PB_Program_Read)
Slaves send master data with printN() all good
master receives data in a loop with AvailableProgramOutput and ReadProgramString
master sends data to the slave with writeprogramstring() (needs #PB_unicode)
Problem is that slave getting data from the master needs to use ReadConsoleData() (I think)
and this is blocking the console!! (as mentioned above)
I tried moving ReadConsoleData to a thread but it still locks the comms so that the slave won't send any more printn()'s until it receives something so it can unlock the consol
There doesn't seem to be any AvailableProgramOutput() for the slave (as mentioned above) and docs for ReadConsoleData() say:
"This function waits until there is some input to read. It will only return without reading data if there was an error or an EOF (End Of File) condition"
I thought the thread would work though in the slave.
I guess I could re-code as a network module and have the slaves spawned by the master reconnect back to it as a tcp server...
Any workarounds for this that people know of? I guess I could have the master send a heartbeat to keep the slaves from locking up....
I can have the master spawn the slaves (runprogram with #PB_Program_Write|#PB_Program_Open|#PB_Program_Read)
Slaves send master data with printN() all good
master receives data in a loop with AvailableProgramOutput and ReadProgramString
master sends data to the slave with writeprogramstring() (needs #PB_unicode)
Problem is that slave getting data from the master needs to use ReadConsoleData() (I think)
and this is blocking the console!! (as mentioned above)
I tried moving ReadConsoleData to a thread but it still locks the comms so that the slave won't send any more printn()'s until it receives something so it can unlock the consol
There doesn't seem to be any AvailableProgramOutput() for the slave (as mentioned above) and docs for ReadConsoleData() say:
"This function waits until there is some input to read. It will only return without reading data if there was an error or an EOF (End Of File) condition"
I thought the thread would work though in the slave.
I guess I could re-code as a network module and have the slaves spawned by the master reconnect back to it as a tcp server...
Any workarounds for this that people know of? I guess I could have the master send a heartbeat to keep the slaves from locking up....
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: How can i run another PB application with Pipe ?
Since both programs are from you,
simply use UDP over a local port.
This is much easier to handle.
simply use UDP over a local port.
This is much easier to handle.
Re: How can i run another PB application with Pipe ?
I think I have something ready ...
STX and ETX are used here for the clean separation of the texts.
UDP Local Network Short Text Sending
STX and ETX are used here for the clean separation of the texts.
UDP Local Network Short Text Sending
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: How can i run another PB application with Pipe ?
I have never used Purebasic and Pipes together.
On Window I use WM_COPYDATA to communicate between two apps on the same computer.
(but now this is a message that does not answer the question, sorry.)
On Window I use WM_COPYDATA to communicate between two apps on the same computer.
(but now this is a message that does not answer the question, sorry.)
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
Re: How can i run another PB application with Pipe ?
It is better to always work with two channels. UDP server only as receiver and UPD client only as sender. This means that two ports are always required.
Slave = Network Server (receiver)
Master = Network Client (sender)
Slave = Network Server (receiver)
Master = Network Client (sender)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: How can i run another PB application with Pipe ?
I think I'll switch to networking.
2-way async comms is not what STDIO is good for it seems
2-way async comms is not what STDIO is good for it seems
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: How can i run another PB application with Pipe ?
sooo, all is not quite fine... I can't stop the two programs talking STDIO to eachother.
The master still spawns all the slaves with RunProgram() (and no flags for connect, open, read write etc)
master and slaves are consol apps and have consols with data on them
but all the slave's printn() data is sent to the master and appears on the masters consol
When I started this the master spawned lots of windows and I had to use hide etc but now I'm using no flags and all IO still goes back.
They talk fine on the network, the slaves phone home but when the master sends the slave data, the slave goes to display it on his consol but there is no window for the slave now for some reason and it appears on the masters consol.
It's like the compiler is not realising I removed the flags (or I'm overlooking something really dumb)
Previously the slaves shows as separate apps in task manager, now they show under the master...
bots(i) = RunProgram("slave.exe" ,Str(i), GetPathPart(ProgramFilename()),#PB_Program_UTF8 )
The master still spawns all the slaves with RunProgram() (and no flags for connect, open, read write etc)
master and slaves are consol apps and have consols with data on them
but all the slave's printn() data is sent to the master and appears on the masters consol
When I started this the master spawned lots of windows and I had to use hide etc but now I'm using no flags and all IO still goes back.
They talk fine on the network, the slaves phone home but when the master sends the slave data, the slave goes to display it on his consol but there is no window for the slave now for some reason and it appears on the masters consol.
It's like the compiler is not realising I removed the flags (or I'm overlooking something really dumb)
Previously the slaves shows as separate apps in task manager, now they show under the master...
bots(i) = RunProgram("slave.exe" ,Str(i), GetPathPart(ProgramFilename()),#PB_Program_UTF8 )
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: How can i run another PB application with Pipe ?
okay fixed,
the slaves need to be compiled as windows and use openconsol() to spawn new windows. if compiled as console then IO goes back to the parent
likewise the processes are now indepenent in task manager
interesting... master compiler options didn't matter though
the slaves need to be compiled as windows and use openconsol() to spawn new windows. if compiled as console then IO goes back to the parent
likewise the processes are now indepenent in task manager
interesting... master compiler options didn't matter though
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein