Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Argument passing

 [1/4] from: al::bri::xtra::co::nz at: 6-Apr-2001 17:22


I got this message directly and thought it might be of benefit to others as well.
> ...I couldn't help noticing the obvious demonstration of your REBOL skills
on rebol.org userlist and wondered if you had any suggestions for a simple but puzzling problem. I say puzzling because in any other programming/scripting language it's not difficult to resolve.
> The question is - How does one pass a dynamic list of arguments to a > REBOL script invoked from: > a) the rebol command line > b) a DOS batch file > c) a Unix shell script? > > I've checked the user lists but to no avail. They either have interactive
prompts or do not parse the arguments from the command line.
> My objective is to run a REBOL script which takes a dynamic list of
arguments and constructs an http CGI request. E.g
> (executed at DOS command-line or batch file, but equally possible from
Unix shell or script)
> c:\>c:\rebol\rebol.exe c:\rebol\scripts\query.r "1234 green rubber ball" > > The idea is that query.r parses the arguments "1234 green rubber ball" and
forms up and executes a REBOL command string like:
> print read
http://www.somewhere.com/cgi-bin/query.pl?customer_id=1234&text1=green&text2 =rubber&text3=ball
> (textn.....textn+1 is the dynamic bit) > > I'd be very grateful for any suggestions you might have. >From the Rebol Core manual (It's available on Rebol HQ site in PDF format
IIRC http://www.rebol.com/download_manual.html ), page 127, 4 - 7: system/script/args should have "the arguments to the script". And:
>> help do
USAGE: DO value /args arg /next DESCRIPTION: Evaluates a block, file, URL, function, word, or any other value. DO is a native value. ARGUMENTS: value -- Normally a file name, URL, or block (Type: any) REFINEMENTS: /args -- If value is a script, this will set its system/script/args arg -- Args passed to a script. Normally a string. (Type: any) /next -- Do next expression only. Return block with result and new position. So: do/args %/c/rebol/scripts/query.r "1234 green rubber ball" should do case A. And, inside %query.r: probe system/script/args should print: "1234 green rubber ball" Then it should be a simple matter to write:
>> b: parse "1234 green rubber ball" none
== ["1234" "green" "rubber" "ball"] to obain the individual words, and then iterate through them with with a 'foreach. I hope that helps! Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [2/4] from: jeff:rebol at: 5-Apr-2001 22:49


Andrew Martin passed along someone's question:
> > The question is - How does one pass a dynamic list of > > arguments to a REBOL script invoked from: a) the rebol > > command line b) a DOS batch file c) a Unix shell script?
With Core 2.5 you can take any number of args from the command line which are split into separate arguments found in system/options/args: Try this script (unix version): ;------------------------------- #!/path/to/rebol REBOL [ Title: "Args checker" ] foreach obj [options script][ print [obj #== mold get in system/:obj 'args] ] quit ;------------------------------- Call the script rargs, put it in your path, make it executable and then try stuff like: rargs 1 2 3 rargs "1 2" 3 etc.. You should see that system/options/args winds up being set to a block containing each argument as a separate string. Then if you want to have fun you can use PARSE on the block and set various options in a pretty simple way: rest: copy [] parse system/options/args [ some [ "-q" (quiet: true) | "-v" (verbose: yes) | "-x" (experimental: on) | set other string! (append rest other) ] ]

 [3/4] from: agem:crosswinds at: 7-Apr-2001 1:44


>>>>>was:
[REBOL] Re: Argument passing From: jeff (view other messages by this author) Date: Thu, 5 Apr 2001 23:18:00 Andrew Martin passed along someone's question:
> > The question is - How does one pass a dynamic list of > > arguments to a REBOL script invoked from: a) the rebol > > command line b) a DOS batch file c) a Unix shell script?
With Core 2.5 you can take any number of args from the command line which are split into separate arguments found in system/options/args: <<<<<<<<<<< b,c) you can also use multi-command shell-scripts before/after the real rebol, maybe prepring an input-file with shell- tools, or a pipe #!/bin/sh #prepare arguments.. /boot/home/rebol/rebol -s $0 $your-args # $0 is scriptname, $@ original shell-arguments. change them.. : #some more shell work.. exit rebol[] [real rebol stuff..]

 [4/4] from: ingo:2b1 at: 11-Apr-2001 19:33


Hi Jeff, some addition on your explanation of arguments ... If Rebol is started without a script, it normally only accepts the rebol arguments, and these are not accessible for a script: rebol -q REBOL/Core 2.5.0.4.2 23-Mar-2001 Copyright 2000-2001 REBOL Technologies. All rights reserved.
>> probe system/options/args
none == none
>>
rebol help REBOL/Core 2.5.0.4.2 Copyright 1997-2001 REBOL Technologies ...
>> probe system/options/args
none == none
>>
But you can get arguments into your user.r, by using -- before your args: rebol -- -q REBOL/Core 2.5.0.4.2 Copyright 1997-2001 REBOL Technologies ...
>> probe system/options/args
["-q"] == ["-q"]
>>
I just thought someone might find this handy. kind regards, Ingo Once upon a time [jeff--rebol--net] spoketh thus: