Discussion:
Better way to check for wget
(too old to reply)
Kevin Wells
2021-01-20 20:58:08 UTC
Permalink
Hi

I use wget in a few of my applications and the check I use to see if
wget is present is in the !Run file:

If "<Wget$Dir>"= "" THEN Error error message.

One of my users has wget in their Libary directory inside !Boot so my
check fails to spot wget and they get that error.

Is their a better way to check for wget, either in the !Run obey file or
in the main application file in BASIC to check for wget?

Thanks.
--
Kev Wells
http://kevsoft.co.uk/ https://ko-fi.com/kevsoft
carpe cervisium
Useless Fact 02 In the artic the sun sometimes appears to be square.
Vince M Hudd
2021-01-22 12:15:28 UTC
Permalink
On 20/01/2021 20:58, Kevin Wells wrote:

[...]
Post by Kevin Wells
Is their a better way to check for wget, either in the !Run obey file or
in the main application file in BASIC to check for wget?
[As well as the current method of checking for a system variable]

Off the top of my head, something along the lines of:

IfThere "<Boot$Dir>.Library.wget" then Set <MyApp$WGet>
If "<Wget$Dir>" <> "" THEN Set <MyApp$WGet>
If "<MyApp$Wget>" = "" THEN Error message

Not sure how sensible that is, TBH, having never needed to do something
similar. (And not having a RISC OS machine switched on to check. e.g. is
there a specific variable used for the library directory? Any other
locations it could potentially be squirrelled away in? etc.)
--
Vince M Hudd - Soft Rock Software - www.softrock.co.uk
RISCOSitory - www.riscository.com
Kevin Wells
2021-01-25 14:23:05 UTC
Permalink
Post by Vince M Hudd
[...]
Post by Kevin Wells
Is their a better way to check for wget, either in the !Run obey file or
in the main application file in BASIC to check for wget?
[As well as the current method of checking for a system variable]
IfThere "<Boot$Dir>.Library.wget" then Set <MyApp$WGet>
If "<Wget$Dir>" <> "" THEN Set <MyApp$WGet>
If "<MyApp$Wget>" = "" THEN Error message
Thanks for this, but Ronald May sent me an idea off list, that got me an
idea which I'm implementing in the application BASIC file rather than
the !Run file, in which I use X wget and send the log into the
applications scrap file and if the scrap file exist or not do what is
required.
Post by Vince M Hudd
Not sure how sensible that is, TBH, having never needed to do something
similar. (And not having a RISC OS machine switched on to check. e.g. is
there a specific variable used for the library directory? Any other
locations it could potentially be squirrelled away in? etc.)
--
Kev Wells
http://kevsoft.co.uk/ https://ko-fi.com/kevsoft
carpe cervisium
Useless Fact 03 You burn 3.5 calories each time you laugh.
Jonathan Harston
2021-01-31 12:23:16 UTC
Permalink
Post by Vince M Hudd
IfThere "<Boot$Dir>.Library.wget" then Set <MyApp$WGet>
If "<Wget$Dir>" <> "" THEN Set <MyApp$WGet>
If "<MyApp$Wget>" = "" THEN Error message
UnSet Wget$Ok
IfThere Run:wget Then Set Wget$Ok "Ok"
If "<Wget$Dir>" <> "" Then Set Wget$Ok "Ok"
If "<Wget$Ok>" = "" THEN Error message

would check for the presence of a runnable wget, but not a local wget
(eg in a module).

The better method would be for your application to just simply issue
a wget command and collect the error if it isn't found.

SYS "XOS_CLI","Wimp_Task wget "+parameters$ TO r0%;f%
IF (f% AND 1) THEN PROCreport("wget not available")

Don't pre-assume. Attempt the action and deal with the response.

"This is a BBC therefore there is no RealTimeClock" -> Wrong
"There is no RTC, therefore there is no RTC" -> Correct

jgh
Theo
2021-01-22 13:49:27 UTC
Permalink
Post by Kevin Wells
Is their a better way to check for wget, either in the !Run obey file or
in the main application file in BASIC to check for wget?
Perhaps something like:

SYS "XWimp_StartTask", "wget -V" TO ;flags%
IF (flags% AND 2) THEN ...

I think you have to use Wimp_StartTask because if you use OS_CLI there's a
risk of replacing your BASIC program with the wget application and being
unable to return when it finishes.

This is a check that wget is either somewhere on your Run$Path or an alias
and can successfully execute - if you can run 'wget -V' you know you have a
functioning program, whereas not being in an expected place is only one of
the things that could go wrong.

Theo
Sprow
2021-01-22 18:20:20 UTC
Permalink
Post by Theo
Post by Kevin Wells
Is their a better way to check for wget, either in the !Run obey file or
in the main application file in BASIC to check for wget?
SYS "XWimp_StartTask", "wget -V" TO ;flags%
IF (flags% AND 2) THEN ...
There's a pecking order for how commands are searched for, if you were to use *wget then
* Is it an alias?
* Is it in a module?
* Is it on Run$Path (which includes the library directory %)?

If you only ever *Run wget that makes things easier because you don't need to worry about aliases or modules, and only Run$Path.
Canonicalise (OS_FSControl 37) the name "wget" for "Run$Path,<Wget$Dir>." and see what you get back.
Sprow.
Kevin Wells
2021-01-25 14:24:03 UTC
Permalink
Post by Theo
Post by Kevin Wells
Is their a better way to check for wget, either in the !Run obey file or
in the main application file in BASIC to check for wget?
SYS "XWimp_StartTask", "wget -V" TO ;flags%
IF (flags% AND 2) THEN ...
The trouble with that is it brings up the contents of wget -V in a
window that has to be closed.

Thanks for this, but Ronald May sent me an idea off list, that got me an
idea which I'm implementing in the application BASIC file rather than
the !Run file, in which I use X wget and send the log into the
applications scrap file and if the scrap file exist or not do what is
required.
Post by Theo
I think you have to use Wimp_StartTask because if you use OS_CLI there's a
risk of replacing your BASIC program with the wget application and being
unable to return when it finishes.
This is a check that wget is either somewhere on your Run$Path or an alias
and can successfully execute - if you can run 'wget -V' you know you have a
functioning program, whereas not being in an expected place is only one of
the things that could go wrong.
Theo
--
Kev Wells
http://kevsoft.co.uk/ https://ko-fi.com/kevsoft
carpe cervisium
I am not an Alcoholic I am a Drunk. Alcoholics go to meetings.
John Williams (News)
2021-01-25 17:12:31 UTC
Permalink
Post by Kevin Wells
I'm implementing in the application BASIC file rather than
the !Run file, in which I use X wget and send the log into the
applications scrap file
You could always send it to null by redirection.

John
Ronald
2021-01-31 23:21:47 UTC
Permalink
Post by John Williams (News)
Post by Kevin Wells
I'm implementing in the application BASIC file rather than
the !Run file, in which I use X wget and send the log into the
applications scrap file
You could always send it to null by redirection.
John
Yes
wget { > null: }
would quit with 'File 'wget not found'
It does run the binary to find out though.
OTH it will find an alias also.

Ifthere Run:wget Then Else Error wget not found
only works for something in the Runpath, but also gives the
option for alternative Error msg or alternative Else ...

IfThere Run:wget Then Else If "<Wget$Dir>" = "" Then wget { > null: }

only trys to run wget in the case of someone not using the
standard issue wget app, but fits in the RunPath check first.
Bordering on too many conditions for an Obey line, wasn't there
an IfNThere available once?
I think it is multiple Elses that lose their way.

Possibly the 'which' utility would be best, includes modules.
but we cant assume that it is installed.
Maybe it should be mandatory.
On a system with alias's possibly hidden away, the 'which' utility
can reduce confusion.

Only been looking at obey file options here
Ronald May

Loading...