Page 1 of 1

main-args different result for executable

Posted: Fri Feb 26, 2016 8:30 am
by hotcore
Hi,

I discovered that (logically) the first os commandline parameter "newlisp" is missing from (main-args) when run from an executable.

Is it possible to detect if a script is run as a script or as an executable?
That way it would be easier to test properly for both cases!

TIA,
Arie

Re: main-args different result for executable

Posted: Fri Feb 26, 2016 9:46 am
by hotcore
Maybe a dumb answer to self:
IF the first argument is the string "newlisp" it should always be a script.
Thx,
Arie

Re: main-args different result for executable

Posted: Fri Feb 26, 2016 10:13 am
by hotcore
So, I tried this out.

I have this code:
(define (mainargs)
(let (osargs (main-args))
(if (= (lower-case (osargs 0)) "newlisp")
(1 osargs))))
And the main code:
(load "mainargs.lsp")

(define (showpath myargs)
(let (pathlist (parse (lower-case (env "PATH")) ";")
osargs (mainargs))
(println "===>" osargs (main-args))
(dolist (line pathlist)
(if (> (length osargs) 1)
(if (not (nil? (find (lower-case (osargs 1)) line)))
(println line))
(println line)))))

(println "=====================================================")
(showpath)
(println "=====================================================")
(exit)
Purpose is to display the constituents of the system PATH env var, with or without a search string specified on the commandline.

The code above does NOT work, because the call (mainargs) returns nil.

However, when I comment out the "load" function line and put the mainargs definition at the top of the code, it does work as expected.

I read in the manual that load does not change contexts.

Any help is much appreciated!

Thx,
Arie

Re: main-args different result for executable

Posted: Fri Feb 26, 2016 10:50 am
by hotcore
I forget to mention important info:
- if run as a script it works
- if run as an executable it does not work

(BTW I'll have to check for both "newlisp" and "newlisp.exe".)

Re: main-args different result for executable (Solved)

Posted: Fri Feb 26, 2016 11:10 am
by hotcore
I found the reason why it failed.
Mainargs did return nil in case "newlisp" was not found. Just a stupid error.
Sorry for bothering you.

But very nice that it is possible to load stuff and still create one executable in the go!

Thanks for being patient with me ;-)
Arie