OS interface
call
Executes a shell command. In most cases, is the same as writing to the command prompt (CLI), but there are a few quirks.
The following code opens Windows Explorer:
>> call "explorer.exe"
== 11272 ; this is the number of the process opened.
This also works:
>> str: "explorer.exe"
== "explorer.exe"
>> call str
== 11916
However, the following code creates the process, but does not open Notepad on screen:
>> call "notepad.exe"
== 4180
If you want a behavior more similar to typing a command on the shell, you must use the refinement /shell
:
>> call/shell "notepad.exe" ;opens notepad on screen
== 6524
Other refinements:
/wait
Runs command and waits until the command you executed is finished to continue. Be careful: If you use /wait on a command that you can't finish (like call "notepad.exe" above), Red will wait... and wait.. indefinetly.
/input - we provide a string! a file! or a binary!, which will be redirected to stdin.
I don't understand this one. Seems as the same as simply call
, as we provide string or a file anyway.
/output
We provide a a string! a file! or a binary! which will receive the redirected stdout from the command. Note that the output is appended.
The following code will create a text file with the shell output for "dir" (a list of files and folders from current path):
>> call/output "dir" %mycall.txt
== 0
This will create a (long) string with the results from "dir":
>> a: ""
== ""
>> call/output "dir" a
== 0
>> a
== { Volume in drive C has no label.^/ Volume Serial Number is BC5 ;...
/show
Force the display of system's shell window (Windows only). Your program will run with windows command prompt open.
>> call/shell/show "notepad.exe"
== 12372
/console
Runs command with I/O redirected to console (CLI console only at present, does not work with Red's normal GUI console).
write-clipboard & read-clipboard
Writes to and reads from the OS clipboard:
>> write-clipboard "You could paste this somewhere you find useful"
== true
>> print read-clipboard
You could paste this somewhere you find useful