Page 1 of 1

Command line: passing open arg ?

Posted: Wed Dec 14, 2011 9:35 pm
by DavMin
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 :(

Re: Command line: passing open arg ?

Posted: Thu Dec 15, 2011 4:12 pm
by DavMin
I see I need to link it into an exe, then I can pass cmd line args. Thanks.

Re: Command line: passing open arg ?

Posted: Thu Dec 15, 2011 8:02 pm
by Lutz
You don't need to link to an .exe to get the command line parameters. If your dl.lsp is:

Code: Select all

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

Code: Select all

~> 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:

Code: Select all

#!/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:

Code: Select all

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

Re: Command line: passing open arg ?

Posted: Thu Dec 15, 2011 9:22 pm
by DavMin
Very cool. Thank you!