RunProgram() Question

Just starting out? Need help? Post your questions and find answers here.
swhite
Addict
Addict
Posts: 801
Joined: Thu May 21, 2009 6:56 pm

RunProgram() Question

Post by swhite »

In the WriteProgramString() documentation it states:
The program to use. It must have been started before with RunProgram() and the #PB_Program_Write flag.
Now lets assume I have a program called RunProgramMgr() that uses RunProgram(MyProgram). Is there a way to have MyProgram write data back to the RunProgramMgr()'s stdIn even though it was not started by RunProgram()? I know I could always write data to a file but I am curious about whether stdIn can be used.

Thanks,
Simon
Simon White
dCipher Computing
Randy Walker
Addict
Addict
Posts: 1092
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: RunProgram() Question

Post by Randy Walker »

swhite wrote: Fri Oct 10, 2025 9:06 pm In the WriteProgramString() documentation it states:
The program to use. It must have been started before with RunProgram() and the #PB_Program_Write flag.
Now lets assume I have a program called RunProgramMgr() that uses RunProgram(MyProgram). Is there a way to have MyProgram write data back to the RunProgramMgr()'s stdIn even though it was not started by RunProgram()? I know I could always write data to a file but I am curious about whether stdIn can be used.

Thanks,
Simon
Hi Simon... I think what you are trying to do is get two separate apps that you created to communicate data with each other. I thought I had a similar need a while back and decided DDE might be the answer, which led me to this thread and might help you:
viewtopic.php?p=627839#p627839
Turned out a better solution for me was to consolidate my two apps into a single app by effectively merging one app into the other using threads.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
mk-soft
Always Here
Always Here
Posts: 6284
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: RunProgram() Question

Post by mk-soft »

Pipes ...
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
User avatar
Piero
Addict
Addict
Posts: 1016
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: RunProgram() Question

Post by Piero »

…also, in theory (I never tried):
"#PB_Program_Connect: Connect another programs output to this programs input."
"When using the #PB_Program_Connect flag, another program must have been started before with #PB_Program_Open and #PB_Program_Read. The number returned when running this program must be passed as the 'SenderProgram' parameter to RunProgram()."
PS: Ooops, I see now that you said "not started with runprogram", so this would probably not help

PPS: There can be various "problems" to get what you need with pipes (shell), e.g., program may need to be run in interactive mode, or you may need its PID………
Last edited by Piero on Sat Oct 11, 2025 11:35 am, edited 2 times in total.
Axolotl
Addict
Addict
Posts: 870
Joined: Wed Dec 31, 2008 3:36 pm

Re: RunProgram() Question

Post by Axolotl »

Well, stdin, stdout, and stderr are usually intended for console applications.

Nevertheless at the Win32 layer, those 3 handles are returned by GetStdHandle_()
I guess you need the API ReadFile_() and WriteFile_() functions to get it running. (educated guess, never tried)
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
Piero
Addict
Addict
Posts: 1016
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: RunProgram() Question

Post by Piero »

Axolotl wrote: Sat Oct 11, 2025 11:19 am Well, stdin, stdout, and stderr are usually intended for console applications.

Nevertheless at the Win32 layer, those 3 handles are returned by GetStdHandle_()
I guess you need the API ReadFile_() and WriteFile_() functions to get it running. (educated guess, never tried)
I dunno **** about win API, but GetStdHandle_ seems more for "general devices" (not apps); hope I'm wrong
Axolotl
Addict
Addict
Posts: 870
Joined: Wed Dec 31, 2008 3:36 pm

Re: RunProgram() Question

Post by Axolotl »

Oh, I am not sure if you are on window or others?
But if so, this might be interests you.... (Attention it is C/C++)
Creating a Child Process with Redirected Input and Output
@Piero: I agree, you are wrong. Please follow the link.
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
Piero
Addict
Addict
Posts: 1016
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: RunProgram() Question

Post by Piero »

Axolotl wrote: Sat Oct 11, 2025 11:53 am Oh, I am not sure if you are on window or others?
But if so, this might be interests you.... (Attention it is C/C++)
Creating a Child Process with Redirected Input and Output
@Piero: I agree, you are wrong. Please follow the link.
Please forgive me; I don't have time to analyze your example code properly, but it SEEMS to me it's not direct inter-applications communication; just kinda filtering general stdout (hope I'm wrong)

PS:

Code: Select all

tell "PB Forum" to tell "Axolotl" to please forgive "Piero"
Post Reply