Remove problem with main-args in script vs executable

Q&A's, tips, howto's

Remove problem with main-args in script vs executable

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

Maybe somebody is interested in the code below.
The main function is to show the contents of the Windows path, line by line. You may specify a search string on the comaand line to filter the output.

More important is the separate code for a function which takes care of the difference in command line arguments between running as a script and running as an executable.

Code to be "included" (loaded) by the main porogram:
Code: Select all
(define (mainargs)
   (letn (osargs (main-args)
            (srch (lower-case (osargs 0))))
      (if (or (= srch "newlisp") (= srch "newlisp.exe"))
         (1 osargs)
         osargs)))


Main program which loads the above code:
Code: Select all
(load "mainargs.lsp")

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

(println "=====================================================")
(showpath)
(println "=====================================================")
(exit)
hotcore
 
Posts: 29
Joined: Fri Aug 26, 2011 1:03 pm

Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests

cron