Command line: passing open arg ?

Q&A's, tips, howto's
Locked
DavMin
Posts: 16
Joined: Fri Dec 09, 2011 8:07 pm

Command line: passing open arg ?

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

DavMin
Posts: 16
Joined: Fri Dec 09, 2011 8:07 pm

Re: Command line: passing open arg ?

Post by DavMin »

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Command line: passing open arg ?

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

DavMin
Posts: 16
Joined: Fri Dec 09, 2011 8:07 pm

Re: Command line: passing open arg ?

Post by DavMin »

Very cool. Thank you!

Locked