main-args different result for executable

For the Compleat Fan

main-args different result for executable

Postby hotcore » Fri Feb 26, 2016 8:30 am

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
 
Posts: 29
Joined: Fri Aug 26, 2011 1:03 pm

Re: main-args different result for executable

Postby hotcore » Fri Feb 26, 2016 9:46 am

Maybe a dumb answer to self:
IF the first argument is the string "newlisp" it should always be a script.
Thx,
Arie
hotcore
 
Posts: 29
Joined: Fri Aug 26, 2011 1:03 pm

Re: main-args different result for executable

Postby hotcore » Fri Feb 26, 2016 10:13 am

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
hotcore
 
Posts: 29
Joined: Fri Aug 26, 2011 1:03 pm

Re: main-args different result for executable

Postby hotcore » Fri Feb 26, 2016 10:50 am

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
 
Posts: 29
Joined: Fri Aug 26, 2011 1:03 pm

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

Postby hotcore » Fri Feb 26, 2016 11:10 am

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
hotcore
 
Posts: 29
Joined: Fri Aug 26, 2011 1:03 pm


Return to Anything else we might add?

Who is online

Users browsing this forum: No registered users and 3 guests

cron