Page 1 of 1

RunProgram("")

Posted: Sat Sep 07, 2024 5:19 am
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).

Re: RunProgram("")

Posted: Sat Sep 07, 2024 5:28 am
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.

Re: RunProgram("")

Posted: Sat Sep 07, 2024 5:37 am
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.

Re: RunProgram("")

Posted: Sat Sep 07, 2024 6:14 am
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).

Re: RunProgram("")

Posted: Sat Sep 07, 2024 6:30 am
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.

Re: RunProgram("")

Posted: Sat Sep 07, 2024 7:38 am
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$)))