How do I start a second program and have it run independent of the first?

316 views
Skip to first unread message

Michael Green

unread,
May 13, 2026, 10:46:25 AMMay 13
to Harbour Users
I want to start a second Harbour program from inside the first. I tried this:
proc main()
store './progname' to outstrv
! @outstrv
return

However, that doesn't work as it is. Advice please. I'm running on FreeBSD.

Alain Aupeix

unread,
May 13, 2026, 2:59:32 PMMay 13
to harbou...@googlegroups.com, Michael Green
Hum, I proceed using hb_ProcessRun() if I need to keep the output of the command,
Else, hb_run()

Example :

local cStdOut:=""
cmd="/usr/"+getenv("home")+"/bin/myprog"
// if I need the output :
hb_Process_Run(cmd,,@cStdOut)
// if I don't need the output and the program must waitthe external program
hb_Run(cmd)
// if I don't need the output and the program must not wait the external program
cmd+=" &"
hb_Run(cmd)


A+
--

Alain Aupeix
Sites web : JujuLand | Pissobi-Lacassagne | Gadel
X.ubuntu 16.04 | H.arbour 3.2.0-1 (r2025-08-22 10:00) | Hw.gui 2.23-8dev (r3792) | G.ramps 5.1.2


bernardm...@gmail.com

unread,
May 14, 2026, 1:35:17 AMMay 14
to Harbour Users

Don Lowenstein

unread,
May 14, 2026, 2:18:58 AMMay 14
to Harbour Users
ShellExecute() is an option.

From: harbou...@googlegroups.com <harbou...@googlegroups.com> on behalf of bernardm...@gmail.com <bernardm...@gmail.com>
Sent: Thursday, May 14, 2026 12:35 AM
To: Harbour Users <harbou...@googlegroups.com>
Subject: Re: [harbour-users] How do I start a second program and have it run independent of the first?
 
GRAPHUS
Warning: The sender @harbour-users@googlegroups​.com might be a spam sender.
powered by Graphus®
--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/f9fef89b-c55d-419c-90b0-4923b70bf6a3n%40googlegroups.com.

Alain Aupeix

unread,
May 14, 2026, 2:52:08 AMMay 14
to harbou...@googlegroups.com, Don Lowenstein

It seems to be Windows exclusively ... and the question was under Linux ...

Michael Green

unread,
May 14, 2026, 6:43:43 AMMay 14
to Harbour Users
FreeBSD being used. Robust, reliable, simple. You should try it.

psac...@gmail.com

unread,
May 14, 2026, 12:02:02 PMMay 14
to Harbour Users
Change

! @outstrv

with

! &outstrv

:-)

Michael Green

unread,
May 20, 2026, 8:51:59 AMMay 20
to Harbour Users
Sorry about the typo, it should have been ampersand '&' of course, not the at '@' symbol. However I'm still having a problem getting the second program to run in spite of endless messing about with 'nohup' and '&'. Googling tells me this is because program two is a child of program one. Google leads me to advice that I need to use 'at' possibly with  'atrun'. However 'at' needs root authority. 

What I'm trying to do is run the program (program 2) that checks to see if an sms reminder is due to send. I want that to run every five minutes until 5:00 pm. I want to be able to start this program (smsreminders) from the start-of-day part of the main program (program 1) and have it continue to run until it checks the time and finds it is after 5:00 pm when if exit automatically. 

I tried this:

store '/path/smsreminders' to outstrv
! &oustrv

with no success. Then I tried:
store 'nohup /path/smsreminders &' to outstrv
! &outstrv

Still no good. 

Please suggest alternative approaches. Thanks.

Francesco Perillo

unread,
May 20, 2026, 9:35:14 AMMay 20
to harbou...@googlegroups.com
I Michael,
so you need to start a daemon and let it run until 5:00pm ... there a lot of things you don't specify and that can be important for your use case

First of all you have to "detach" the child executable from the parent and close all relationships, primarily the standard I/O channels, stdio, stdout, stderr. So from the program I will do something like fclose(0); fclose(1); fclose(2)

Another way to have the same effect is to do when you start the program
store '/path/smsreminders > /dev/null 2>&1' to outstrv
should be ok

But I think there is one more thing missing: you have to tell the operating system that you want to detach so it should actually be:
store '/path/smsreminders > /dev/null 2>&1 &' to outstrv

nohup won't kill your program when you logout.

As I said, too few infos about your specific setup to be more precise...

psac...@gmail.com

unread,
May 20, 2026, 1:26:46 PMMay 20
to Harbour Users
As your source code shows, "progname" file must be located in current program path before launching it.  Try to remove "./" to search progname in current Linux paths for executable files, or write full path to progname location.

:-)

El miércoles, 13 de mayo de 2026 a las 16:46:25 UTC+2, Michael Green escribió:

psac...@gmail.com

unread,
May 20, 2026, 1:30:26 PMMay 20
to Harbour Users
Please note that Linux filenames are different in upper and lower cases.  You must write path to progname and progname file exactly like path and filename are stored in your hard drive.

:-)

El miércoles, 13 de mayo de 2026 a las 16:46:25 UTC+2, Michael Green escribió:

psac...@gmail.com

unread,
May 20, 2026, 1:32:36 PMMay 20
to Harbour Users
... And progname file must be marked with +x (executable file) attribute for current or all linux users.

:-)

El miércoles, 13 de mayo de 2026 a las 16:46:25 UTC+2, Michael Green escribió:

psac...@gmail.com

unread,
May 20, 2026, 1:49:55 PMMay 20
to Harbour Users
I forget to say you progname file must be marked too with +r (readable) file attribute for current Linux user or all Linux users.  If you did not make this, Linux can not found the progname file.

:-)

El miércoles, 13 de mayo de 2026 a las 16:46:25 UTC+2, Michael Green escribió:

Steve Litt

unread,
May 20, 2026, 8:47:16 PM (14 days ago) May 20
to harbou...@googlegroups.com
Francesco Perillo said on Wed, 20 May 2026 15:34:59 +0200

>I Michael,
>so you need to start a daemon and let it run until 5:00pm ... there a
>lot of things you don't specify and that can be important for your use
>case

Easier yet, the daemon can run 24*7*365 and just function between
morning and 5:00pm. Then the daemon can (I presume) send a USR1 or USR2
interrupt to the program being run manually. If Harbour can't deal with
interrupts, a sentinel file can be laid down and checked for.


SteveT

Steve Litt

http://444domains.com

Reply all
Reply to author
Forward
0 new messages