GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Download
  • News
  • Community
  • Resources
  • Language Reference
  • SmallBASIC Manual

This view

  • Original page
  • New address

GeezerVison is showing smallbasic.github.io — SmallBASIC | RUN

Edit History

RUN

[s =] RUN cmdstr

Home > Reference > System

Loads a secondary copy of the system shell and executes a program or a shell command given by the string cmdstr. The execution of the calling BASIC program will be stopped and control returns to the BASIC program once the system command has completed. If RUN is called as a function, the return value s holds the text output of the executed command as a string.

System commands, especially on Linux, are very powerful, and can add lots of valuable features to a SmallBASIC program. With system commands you can configure the COM port, send email (Linux at least), get lots of information about the environment, etc.

In the Android version you can use s = RUN to look at information in the /proc file system.

See EXEC if control should return to the BASIC program immediately.

Use RUN in Windows

In Windows (tested with Win10) you have to call the programm cmd which opens a command line window. The command you want to execute will be a parameter of cmd. Additional the parameter /C needs to be added to quit the command line window after execution of the command.

Example 1: RUN as a function

s = run("cmd /C dir")                              ' Execute DIR and
print s                                            ' print a list of files in the current directory

s = run("cmd /C copy rename.txt rename1.txt")      ' Copy a file (please create the file rename.txt before testing)
print s                                            ' Prints the text output of copy

Example 2: RUN as procedure

run("cmd /C copy rename.txt rename1.txt")          ' Copy a file (please create the file rename.txt before testing)
    
run("cmd /C notepad.exe")                          ' Start Notepad and wait until Notepad was closed        

Use RUN in Linux

Commands to execute are case sensitive in Linux. Each command shell has an unique environment-variables-table; which means that you cannot always share environment variables with commands executed by RUN.

Example 1: RUN as a function

s = Run("ls")                                      ' Execute ls and print a list of files in the
print s                                            ' current directory

s = run("cp rename.txt rename1.txt")               ' Copy a file (please create the file rename.txt before testing)
print s                                            ' Prints the text output of cy

Example 2: RUN as procedure

run("cp rename.txt rename1.txt")                   ' Copy a file (please create the file rename.txt before testing)
    
run("gedit")                                       ' Start gedit (if installed) and wait until gedit was closed        

Other Examples

Example 1: Querry whether Linux or Windows is used

const IS_LINUX = (Left(HOME, 1) = "/")  ' Check if it's a Linux system
const IS_WINDOWS = Not IS_LINUX

print "LINUX:   " + IS_LINUX
print "Windows: " + IS_WINDOWS
Code samples using RUN
000 hello.bas   001 3 ways to print hello 5 times.bas   006 arrays+.bas   7gables.bas   another look at trig functions.bas   Balleta 2-11-15.bas   biorythms.bas   Chaos_1xt.bas   Chaos_NPhase.bas   chess.bas   dogstar5.bas   draw rectangle.bas   fibanacci3.bas   fire demo.bas   first factors mga.bas   g2 Life.bas   g3 Life.bas   g4 Life.bas   g5 Life.bas   g6 Life.bas   g_col_09.bas   galgenmann.bas   hex.bas   irc-bot.bas   loancalc.bas   mandel3.bas   memoryTest.bas   memorytest.bas   mira.bas  
System
CHAIN   COMMAND   CWD   DELAY   ENV   ENV   EXEC   EXPORT   FRE   HOME   IMPORT   INCLUDE   MAXINT   NIL   OPTION   PAUSE   PI   PROGLINE   RANDOMIZE   RUN   SBVER   SELF   STKDUMP   TROFF   TRON   UNIT  
This page was last edited on Mon, 19 May 2025 20:44:43 +0930 | Markdown processed with pandoc 3.1.12.1
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.