Home   Archive   Permalink


How do I pass a parameter from one script to another script ?
e.g if I have script1.r and script2.r
and I want to pass a parameter "hello" from within script1.r to script2.r
e.g in script1.r I try something like this
do %script2.r "Hello"
then in script2.r how do i retrieve the parameter "Hello"
I tried, the system/script/args in script2.r it did not work.
I tried the system/options/args in script2.r too it did not work.

posted by:   PASS PARAMETERS       18-Oct-2017/21:23-7:00

You can try:
do/args %script2.r "Hello"
Then check system/script/args in %script2.r

posted by:   Chris       19-Oct-2017/1:08:34-7:00

You can also save values to a third file:
write %data "Hello"
write %script2.r "R E B O L [] print read %data halt"
launch %script2.r
Or if you need to pass data to a second script in real time, send it over a network connection:
write %script2.r {R E B O L []    
port: open/lines tcp://localhost:55555
insert port ask "Send: "}
launch %script2.r
port: first wait open/lines tcp://:55555
print join "Received: "first wait port
Additionally, you can write data directly into a dynamically created script, and then execute that script some time later:
x: "Hello"
write %script2.r rejoin [{R E B O L [] print "} x {" halt}]
launch %script2.r

posted by:   Nick       19-Oct-2017/8:09:23-7:00

(remove the spaces in the REBOL header in each of the examples above)

posted by:   Nick       19-Oct-2017/8:18:31-7:00

BTW, you can also use 'call to run command line arguments:
call/show "rebol -h"

posted by:   Nick       19-Oct-2017/10:05:10-7:00

thank you Nick for the different ways of passing info between scripts.

posted by:   PASS PARAMETERS       22-Oct-2017/10:26:21-7:00

If you use Windows, you could use the clipboard if you don't suddenly use it for something else and cause a conflict:
R E B O L []
write %passtest2.r {R E B O L []
PASSED-TEXT: read clipboard://
print ["passtest2 has received " PASSED-TEXT]
write clipboard:// "Hello"
print "Calling passtest2.r"
launch %passtest2.r
print "passtest2.r has been called"

posted by:   Steven White       23-Oct-2017/13:15:44-7:00

As a side note of possible interest, I ran across a similar problem at work and found out that Windows has a program called clip.exe that can load the clipboard. This makes it possible for a powershell script to pass text to a REBOL script. In powershell you could have something like:
Then have the powershell script run the REBOL interpreter with the --script option to specify the REBOL script. In REBOL do:
PASSEDTEXT: read clipboard://
A bit off topic but I thought I would mention it while it is fresh in my memory.

posted by:   Steven White       28-Oct-2017/11:02:46-7:00

BTW, you can also use 'call to run command line arguments:
call/show "rebol -h"
If you were running a command line argument that could do several things could you run make a GUI window with Rebol then pass arguments by calling a shell every time? What would close the shell? Does it close after being called or would you be continuously starting new shells every time you sent arguments to a CL program?

posted by:   Sam the Truck       1-Nov-2017/12:10:52-7:00

You can use call/show show to run a script on the command line, and it executes in a new Rebol process. Nothing else about the script or the process is different from any other Running Rebol script. Close the process within the script if you want:
call/show {rebol script2.r}

posted by:   Nick       2-Nov-2017/7:35:24-7:00


posted by:   Sam the Truck       23-Jan-2018/19:06:29-8:00