newLISP Fan Club

Forum => newLISP in the real world => Topic started by: DavMin on December 14, 2011, 01:35:38 PM

Title: Command line: passing open arg ?
Post by: DavMin on December 14, 2011, 01:35:38 PM
I'm running a single program in newlisp and want to pass an argument:



newlisp dl.lsp '123456'



I doesn't seem like newlisp accepts openargs. Did I miss something?



I suppose I could write it to a text file and have the program read the text file to retrieve the info :(
Title: Re: Command line: passing open arg ?
Post by: DavMin on December 15, 2011, 08:12:10 AM
I see I need to link it into an exe, then I can pass cmd line args. Thanks.
Title: Re: Command line: passing open arg ?
Post by: Lutz on December 15, 2011, 12:02:04 PM
You don't need to link to an .exe to get the command line parameters. If your dl.lsp is:


(println "The command line args are: " (main-args))
(println "The last one is: " (int (main-args -1)))
(exit)


then:


~> newlisp dl.lsp 12345
The command line args are: ("newlisp" "dl.lsp" "12345")
The last one is: 12345
~>


Note, that all arguments are passed as strings, even if not quoted.



On UNIX you could add as first line in the script:
#!/usr/bin/newlisp

(println "The command line args are: " (main-args))
(println "The last one is: " (int (main-args -1)))
(exit)


After giving dl.lsp executable permissions, you can do:


~> ./dl.lsp 12345
The command line args are: ("/usr/bin/newlisp" "./dl.lsp" "12345")
The last one is: 12345
~>
Title: Re: Command line: passing open arg ?
Post by: DavMin on December 15, 2011, 01:22:06 PM
Very cool. Thank you!