Page 1 of 1
Get a string back from another program
Posted: Wed Apr 20, 2022 11:53 am
by StarWarsFan
Let me describe what I have here and then ask the question:
Program 1 calls Program 2 using
RunProgram("Program2.exe", "/check"", "", #PB_Program_Open | #PB_Program_Read)
Program 2 generates the MD5Sum of itself using FileFingerPrint, i.e.
UseMD5Fingerprint() : st$= UCase(FileFingerprint(GetCurrentDirectory()+"Program2.exe",#PB_Cipher_MD5))
Now how do I get that MD5Sum (string) back from program2 so program 1 can work with it?
I am calling with "#PB_Program_Read" but I get no idea from the documentation as to how to write to where that read wants to read from.
(The documentation is very unclear to me here and I must be missing something totally obvious maybe)
WriteProgramString only writes to stdIN, but in this example I believe I must write to stdOUT (!) - help please !!!
Re: Get a string back from another program
Posted: Wed Apr 20, 2022 11:56 am
by BarryG
Re: Get a string back from another program
Posted: Wed Apr 20, 2022 3:06 pm
by Jeff8888
I have used get and set environmentalvariable commands to pass strings. From PB help file for info:
SetEnvironmentVariable(Name$, Value$)
Description
Creates an environment variable in the environment block of this program with given name and value. If a variable with this name already existed, its content will be changed to the new value.
The environment block of the program is passed on to other programs executed with RunProgram(), so this method may be used to pass on information to a program executed by this program. (The executed program may use GetEnvironmentVariable() to read the variables.)
Re: Get a string back from another program
Posted: Wed Apr 20, 2022 4:56 pm
by Axolotl
Hi StarWarsFan,
i believe that this should be easy with the following steps:
1. Use OpenConsole() and PrintN() in your Program2 to write the info.
2. Read the output by Program1 with ReadProgramString().
Re: Get a string back from another program
Posted: Wed Apr 20, 2022 7:10 pm
by mk-soft
Re: Get a string back from another program
Posted: Wed Apr 20, 2022 7:18 pm
by StarWarsFan
Thanks, Barry, always a helping hand, you!
I am now looking into Netmaestro's way, though the idea to exchange that using an environment variable seems the most elegant and easiest way to get this simple job done. I surely do not wish to academically blow it up with network,udp or even bigger.
THANKS
Last question: Can I somehow hide the console if I try that? I do not want that the user sees a console for this simple purpose!
Re: Get a string back from another program
Posted: Thu Apr 21, 2022 10:35 am
by sec
StarWarsFan wrote: Wed Apr 20, 2022 7:18 pm
Thanks, Barry, always a helping hand, you!
I am now looking into Netmaestro's way, though the idea to exchange that using an environment variable seems the most elegant and easiest way to get this simple job done. I surely do not wish to academically blow it up with network,udp or even bigger.
THANKS
Last question: Can I somehow hide the console if I try that? I do not want that the user sees a console for this simple purpose!
Hide console with RunProgram()'s #PB_Program_Hide
Re: Get a string back from another program
Posted: Thu Apr 21, 2022 10:32 pm
by Axolotl
If Program2 is or could be a console app I recommend my first answer.
If both apps are windows apps I would use WM_COPYDATA.
Hoestly, I use this inter-app communication in my apps with success.