Interacting with the operating system
Some of the things you must be able to do when writing apps include getting information at startup, starting up a different program from within your app, and using the OS clipboard. Here, we'll show you how this is done in Red.
Getting input from command-line arguments
Command-line arguments are captured in the system/script/args
word. It is one string in which all arguments are stored, separated by a space:
;-- see Chapter10/args.red: print system/script/args ;== "78 A Red" type? system/script/args ;== string! args: split system/script/args " ";== ["78" "A" "Red"] print ["Number of command-line arguments:"length? args] ;== Number of command-line arguments: 3 foreach arg args [ print arg ] ; 78 ; A ; Red
We can use split
to obtain the separated arguments in an args
series, and start using them.
To see the output, start the program with red args.red 78 A Red
, or after compiling with red -r
, start it with...