main-args different result for executable

Started by hotcore, February 26, 2016, 12:30:19 AM

Previous topic - Next topic

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

hotcore

#1
Maybe a dumb answer to self:

IF the first argument is the string "newlisp" it should always be a script.

Thx,

   Arie

hotcore

#2
So, I tried this out.



I have this code:
Quote(define (mainargs)

   (let (osargs (main-args))

      (if (= (lower-case (osargs 0)) "newlisp")

         (1 osargs))))


And the main code:
Quote(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

hotcore

#3
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".)

hotcore

#4
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