Command line: passing open arg ?

Started by DavMin, December 14, 2011, 01:35:38 PM

Previous topic - Next topic

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

DavMin

#1
I see I need to link it into an exe, then I can pass cmd line args. Thanks.

Lutz

#2
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
~>

DavMin

#3
Very cool. Thank you!