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/
-><-


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to