PASSING PARAMETERS FROM ONE SCRIPT TO ANOTHER

Started by PASS PARAMETERS on 18-Oct-2017/21:23-7:00
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.
You can try: do/args %script2.r "Hello" Then check system/script/args in %script2.r
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
(remove the spaces in the REBOL header in each of the examples above)
BTW, you can also use 'call to run command line arguments: call/show "rebol -h"
thank you Nick for the different ways of passing info between scripts.
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] halt } write clipboard:// "Hello" print "Calling passtest2.r" launch %passtest2.r print "passtest2.r has been called" halt
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: $PASSEDTEXT = "Hello" $PASSEDTEXT | clip 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.
"... 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?
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}
Thanks.

Reply