OS interface


native! call        Red Wiki                Red-by-example                MyCode4fun

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

Generate a beep (tone, duration). Must have Powershell installed.


 >> call "powershell [console]::beep(1000,500)"

 == 1088



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 script will run with windows command prompt open.

>> call/shell/show "notepad.exe"
== 12372

I believe this will have some use in the future, when Red allows using the /console option from the GUI console. Maybe.

/console

Runs command with I/O redirected to console (CLI console only at present, does not work with Red's normal GUI console).


Open Red on system console, as explained here, then, using the /console refinement on call, you the cmd output on the same console as Red:


C:\Users\AndrĂ©\Documents\RedIDE>red-063.exe --cli  

--== Red 0.6.3 ==--                                

Type HELP for starting information.                

                                                   

>> call/console "echo hello world"                 

hello world                                        

== 0                                                

>>



native! 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


< Previous topic                                                                                          Next topic >