RunProgram("")

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

RunProgram("")

Post by AZJIO »

Do you think RunProgram("") is an error? What if the file is deleted? This is also not the correct path to the file, why is it better than an empty line? My variable turned out to be empty and the code generated an error (discovered on Linux).
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: RunProgram("")

Post by BarryG »

AZJIO wrote: Sat Sep 07, 2024 5:19 amDo you think RunProgram("") is an error?
The debugger warns you if no file is specified, so no, not an error.
AZJIO wrote: Sat Sep 07, 2024 5:19 amWhat if the file is deleted?
A file can't be deleted unless you specify a file, which you haven't.
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: RunProgram("")

Post by AZJIO »

BarryG wrote: Sat Sep 07, 2024 5:28 am A file can't be deleted.

Code: Select all

RunProgram(PathConfig$ + "AdvancedSearch.chm")
the user deletes the specified CHM file and doesn't care what you think about it. And RunProgram is trying to run a non-existent file.
Example number two:
I read the path editor=path from the ini file and get an empty string due to the fact that an empty value is valid for the ini file.
Reading the way

Code: Select all

Global editor$ = "xdg-open"
editor$ = ReadPreferenceString("editor", editor$)
RunProgram(editor$, ......
I'm adding a check

Code: Select all

If Not Asc(editor$)
	editor$ = "xdg-open"
EndIf
Why is checking for an invalid path not needed, but checking for an empty string is?

I don't think that RunProgram() will be executed in a high-speed loop and run the executable file 100 times per second, so checking for an empty string can be done.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: RunProgram("")

Post by BarryG »

Oh, you meant if the user deletes the file, and not deleted with RunProgram() itself (with "del" or something). I see.

But, it's still no problem because you're checking the return value of RunProgram(), right?

Code: Select all

Debug RunProgram(PathConfig$ + "NoSuchFile") ; Returns 0 (meaning failed).
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: RunProgram("")

Post by AZJIO »

Code: Select all

editor$ = ""
RunProgram(editor$, ......
This causes an error in the IDE, the line is marked in red. (Linux. haven't tested it on Windows)
If the path is incorrect, the debugger skips this line.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: RunProgram("")

Post by BarryG »

Hmm, good catch. This returns 1 (success) and opens Explorer.exe for me:

Code: Select all

DisableDebugger
editor$=""
MessageRequester("Result",Str(RunProgram(editor$)))
Post Reply