ProgramExitCode(), but as a string

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

ProgramExitCode(), but as a string

Post by StarWarsFan »

I wonder if there is a way to not only return an integer as exit value, but a string.

At the moment I let the client program write its string to a temp file and the host program reads the info from there.
But I would really like to have a more elegant way to pass the info back.

Is there maybe a function that I have missed?
Last edited by StarWarsFan on Wed Sep 08, 2021 9:29 am, edited 1 time in total.
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.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: ProgramExitCode(), but as a string

Post by Demivec »

StarWarsFan wrote: Wed Sep 08, 2021 12:48 am I wonder if there is a way to not only return an integer as exit value, but a string.

Is there maybe a function that I have missed?
No, there isn't a missing function. In general, the possible values returned are determined by each program and PureBasic only allows an 8-bit numeric code. Notwithstanding that, the value zero generally signals "Success" or no errors and other values represent degrees or varieties of errors and failure.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: ProgramExitCode(), but as a string

Post by StarWarsFan »

//
Last edited by StarWarsFan on Wed Sep 08, 2021 9:28 am, edited 1 time in total.
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.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: ProgramExitCode(), but as a string

Post by Marc56us »

StarWarsFan wrote: Wed Sep 08, 2021 8:27 am But how do I then send back a string to the calling programm?
SetEnvironmentVariable()
:wink:
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: ProgramExitCode(), but as a string

Post by StarWarsFan »

//
Last edited by StarWarsFan on Wed Sep 08, 2021 9:27 am, edited 1 time in total.
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.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: ProgramExitCode(), but as a string

Post by Demivec »

Marc56us wrote: Wed Sep 08, 2021 8:53 am
StarWarsFan wrote: Wed Sep 08, 2021 8:27 am But how do I then send back a string to the calling programm?
SetEnvironmentVariable()
:wink:
@Marc56us: Doesn't that function only to send or provide information from a parent process to a child process and not the other way around?
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: ProgramExitCode(), but as a string

Post by Marc56us »

Demivec wrote: Wed Sep 08, 2021 9:01 am Doesn't that function only to send or provide information from a parent process to a child process and not the other way around?
Yes, this seems to be the case in PB :cry: . I just tested (including with an EXE launched from the same CMD.)
But it works in other languages. :|
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: ProgramExitCode(), but as a string

Post by StarWarsFan »

In that case you guys can delete your posts and the initial question still stands:

How do I then send back a string to the calling programm?


At the moment I let the client program write its string to a temp file and the host program reads the info from there.
But I would really like to have a more elegant way to pass the info back.
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.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: ProgramExitCode(), but as a string

Post by Marc56us »

StarWarsFan wrote: Wed Sep 08, 2021 9:26 am In that case you guys can delete your posts [...]
StarWarsFan, please don't shout: If you have already tried, you will see that you can only delete your answer if it is the last one in the topic.
You can edit it or clear it, but as you can see after you have edited your secont post (//), following reply are inconsistant.
Finally, if you delete any response that is not works, you may see other users repost the same thing a little later.
(ask moderators to clean unwanted reply if you want. You can also click on the exclamation point of each article to request its removal.)
:wink:
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ProgramExitCode(), but as a string

Post by NicTheQuick »

You can write directly to the standard out using Print() and the other program can read that output using ReadProgramString(). That is a common thing used all the time with command line tools in Linux for example. Refer to the help to get examples and further info.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
jacdelad
Addict
Addict
Posts: 1436
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: ProgramExitCode(), but as a string

Post by jacdelad »

Or use TCP on the same computer?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: ProgramExitCode(), but as a string

Post by Olli »

If the output code is a 64-bits integer, you can compress a 8-characters text filename and store your string or your strings list in a txt file ! :mrgreen:
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Re: ProgramExitCode(), but as a string

Post by pdwyer »

Is one program run by the other? if so, as NicTheQuick wrote, STDIO is the normal way to do this locally

if host and client are independent perhaps networking tech would work better. A simple type of restApi kind of thing would be enough
Or via a database, queue or messaging system (but these involve an extra external component)

are there multiple clients for the host?
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
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: ProgramExitCode(), but as a string

Post by StarWarsFan »

Marc56us wrote: Wed Sep 08, 2021 9:39 am
StarWarsFan wrote: Wed Sep 08, 2021 9:26 am In that case you guys can delete your posts [...]
StarWarsFan, please don't shout:
Nobody has shouted. THIS WOULD BE SHOUTING IN CAPITALS FOR EXAMPLE. But I have not done that.

Much more important than such petty stuff: Still I have no functioning solution.
Seems you guys have no working example either and I simply continue to use my solution or must experiment a bit more till I get it done myself...
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.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ProgramExitCode(), but as a string

Post by NicTheQuick »

StarWarsFan wrote: Mon Sep 13, 2021 6:36 pm Much more important than such petty stuff: Still I have no functioning solution.
Seems you guys have no working example either and I simply continue to use my solution or must experiment a bit more till I get it done myself...
It's easy to create a working solution out of all we said up to now. The question is: Do you think we create the code for you or will you code it by yourself?
There are also a few unanswered questions for you. If you would answer these we could help you better.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply