RunProgram() without parameter in IDE

Just starting out? Need help? Post your questions and find answers here.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

RunProgram() without parameter in IDE

Post by blueznl »

RunProgram("")

Works as expected in the compiler, but throws an error in the IDE (5.73LTS and 6.0A4)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: RunProgram() without parameter in IDE

Post by jacdelad »

What...what is the expected outcome to use it with an empty string? I don't think that's intended.
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
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: RunProgram() without parameter in IDE

Post by BarryG »

blueznl wrote: Mon Oct 04, 2021 10:16 amWorks as expected in the compiler, but throws an error in the IDE (5.73LTS and 6.0A4)
What error are you getting? I get a message that a filename is needed (in the IDE).
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: RunProgram() without parameter in IDE

Post by blueznl »

That is the error :wink: That shouldn't happen according to the documentation, and it doesn't happen once compiled.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Re: RunProgram() without parameter in IDE

Post by ebs »

That shouldn't happen according to the documentation
It looks like that's exactly the error you should get in the IDE ("RunProgram(): A filename must be specified.")
According to the documentation, the first parameter (Filename$) is not optional, and therefore it has to be supplied.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: RunProgram() without parameter in IDE

Post by BarryG »

blueznl wrote: Mon Oct 04, 2021 8:38 pmThat shouldn't happen according to the documentation
I can't see any mention of this in the docs?
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: RunProgram() without parameter in IDE

Post by jacdelad »

BarryG wrote: Tue Oct 05, 2021 10:03 pm
blueznl wrote: Mon Oct 04, 2021 8:38 pmThat shouldn't happen according to the documentation
I can't see any mention of this in the docs?
Filename$ The executable name including its path.
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
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: RunProgram() without parameter in IDE

Post by BarryG »

jacdelad wrote: Wed Oct 06, 2021 12:16 am
BarryG wrote: Tue Oct 05, 2021 10:03 pm
blueznl wrote: Mon Oct 04, 2021 8:38 pmThat shouldn't happen according to the documentation
I can't see any mention of this in the docs?
Filename$ The executable name including its path.
No, I mean where in the docs does it say an error will be thrown for a null filename (as bluenzl claims)? It doesn't. In fact, the manual doesn't say anything at all about a missing filename. It just assumes one will be supplied.
AZJIO
Addict
Addict
Posts: 1316
Joined: Sun May 14, 2017 1:48 am

Re: RunProgram() without parameter in IDE

Post by AZJIO »

Filename$ does not imply an empty string, since in this case it makes no sense to use the function.
If you sit down to eat using the emptiness in the plate, then in this case it makes no sense to sit down to eat.

I assume that you are using a variable that, for some unforeseen reason, turned out to be an empty string. Make a self-check that the file exists before sending it to the function.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: RunProgram() without parameter in IDE

Post by blueznl »

(Before deliving deeper, this is a very minor thing, so no worries.)

Still I have to disagree with you guys, for two reasons (sorry :-) )

1. Let's look at the docs:
Return value

Nonzero if the program has been successfully launched, zero otherwise.

If #PB_Program_Open was included in the Flags, the return-value is a number that identifies the program. It may be used in calls to get information about the program such as ReadProgramString() or ProgramExitCode() or other functions mentioned above.
If it has been succesfully launched, then it should return a non-zero value.

It didn't sucesfully launch, thus it should return a zero, instead it errors out. The doc doesn't state it must be a valid string, it only states that it will return a value depending on the success of the call.

Then, 2. (more a personal thing) I strongly believe the IDE and the compiled program should work the same as much as possible. I suspect Fred simply built in an extra check to catch this error upfront.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: RunProgram() without parameter in IDE

Post by blueznl »

AZJIO wrote: Wed Oct 06, 2021 9:33 am Filename$ does not imply an empty string, since in this case it makes no sense to use the function.
If you sit down to eat using the emptiness in the plate, then in this case it makes no sense to sit down to eat.

I assume that you are using a variable that, for some unforeseen reason, turned out to be an empty string. Make a self-check that the file exists before sending it to the function.
That latter would be a little silly, as you would have to parse the full path to catch any error. Try RunProgram("Notepad.exe"). It'll work. Now, WHERE is "notepad.exe"?

And why would such a check be necessary when compiled?

Also, if I had to check the validity of the string myself, then why does the function return a value at all if (not) succesful? :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
AZJIO
Addict
Addict
Posts: 1316
Joined: Sun May 14, 2017 1:48 am

Re: RunProgram() without parameter in IDE

Post by AZJIO »

blueznl wrote: Thu Oct 07, 2021 3:05 pmWHERE is "notepad.exe"?

Code: Select all

Define Path$ = "Notepad.exe"
PathFindOnPath_(@Path$, #Null)
Debug Path$
I don't know how to do it right

Code: Select all

Define path.String
path\s = "Notepad.exe"
; PathFindOnPath_(path\s, #Null)
PathFindOnPath_(@path\s, #Null)
Debug path\s
It will not go beyond the allocated memory here

Code: Select all

Procedure.s PathFind(path$)
	Protected tmp$
	tmp$ = Space(#MAX_PATH)
	PokeS(@tmp$, path$)
; 	Wow64EnableWow64FsRedirection(0) ; https://www.purebasic.fr/english/viewtopic.php?p=481621#p481621
	If PathFindOnPath_(@tmp$, #Null)
		path$ = tmp$
	EndIf
; 	Wow64EnableWow64FsRedirection(1) 
	ProcedureReturn path$
EndProcedure

Debug PathFind("Notepad.exe")
Last edited by AZJIO on Wed Dec 22, 2021 9:46 pm, edited 5 times in total.
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: RunProgram() without parameter in IDE

Post by freak »

The debugger just tells you about a potential error in your command arguments. It is the same for many PB commands. If you don't like that just use "DisableDebugger" to disable such checks.
quidquid Latine dictum sit altum videtur
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: RunProgram() without parameter in IDE

Post by blueznl »

No no, it's fine. It just threw me a curvebal when testing stuff from the IDE.

I simply wasn't expecting it when reading the documentation (which suggests I would get a return value).

If it's by design, fine.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: RunProgram() without parameter in IDE

Post by Rinzwind »

It is indeed weird that an empty string "" is handled differently from let's say "a". Both should just return 0. "" in a compiled exe even opens file explorer for whatever reason.
Post Reply