Get a string back from another program

Just starting out? Need help? Post your questions and find answers here.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Get a string back from another program

Post 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) :oops:

WriteProgramString only writes to stdIN, but in this example I believe I must write to stdOUT (!) - help please !!!
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: Get a string back from another program

Post by BarryG »

Netmaestro's code here has worked for me -> https://www.purebasic.fr/english/viewtopic.php?t=29781
Jeff8888
User
User
Posts: 42
Joined: Fri Jan 31, 2020 6:48 pm

Re: Get a string back from another program

Post 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.)
Axolotl
Addict
Addict
Posts: 838
Joined: Wed Dec 31, 2008 3:36 pm

Re: Get a string back from another program

Post 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().
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6252
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Get a string back from another program

Post by mk-soft »

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
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Get a string back from another program

Post 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!
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: Get a string back from another program

Post 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
Axolotl
Addict
Addict
Posts: 838
Joined: Wed Dec 31, 2008 3:36 pm

Re: Get a string back from another program

Post 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.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply