System Functions

In this chapter we are going to learn about the system functions

  • System()
  • SysGet()
  • IsMSDOS()
  • IsWindows()
  • IsWindows64()
  • IsUnix()
  • IsMacOSX()
  • IsLinux()
  • IsFreeBSD()
  • IsAndroid()
  • Windowsnl()
  • Get Command Line Arguments
  • Get Active Source File Name
  • CurrentDir()
  • ExeFileName()
  • ChDir()
  • ExeFolder()

System() Function

We can execute system commands using the system() function

Syntax:

System(cCommand)

Example:

System("myapp.exe")     # Run myapp.exe
System("ls")            # print list of files

SysGet() Function

We can get environment variables using the Get() function

Syntax:

SysGet(cVariable)

Example:

see sysget("path")              # print system path information

IsMSDOS() Function

We can check if the operating system is MSDOS or not using the IsMSDOS() function

Syntax:

IsMSDOS() ---> Returns 1 if the operating system is MS-DOS, Returns 0 if it's not

IsWindows() Function

We can check if the operating system is Windows or not using the IsWindows() function

Syntax:

IsWindows() ---> Returns 1 if the operating system is Windows, Returns 0 if it's not

IsWindows64() Function

We can check if the operating system is Windows 64bit or not using the IsWindows64() function

Syntax:

IsWindows64() ---> Returns 1 if the operating system is Windows64, Returns 0 if it's not

IsUnix() Function

We can check if the operating system is Unix or not using the IsUnix() function

Syntax:

IsUnix() ---> Returns 1 if the operating system is Unix, Returns 0 if it's not

IsMacOSX() Function

We can check if the operating system is Mac OS X or not using the IsMacOSX() function

Syntax:

IsMacOSX() ---> Returns 1 if the operating system is Mac OS X, Returns 0 if it's not

IsLinux() Function

We can check if the operating system is Linux or not using the IsLinux() function

Syntax:

IsLinux() ---> Returns 1 if the operating system is Linux, Returns 0 if it's not

IsFreeBSD() Function

We can check if the operating system is FreeBSD or not using the IsFreeBSD() function

Syntax:

IsFreeBSD() ---> Returns 1 if the operating system is FreeBSD, Returns 0 if it's not

IsAndroid() Function

We can check if the operating system is Android or not using the IsAndroid() function

Syntax:

IsAndroid() ---> Returns 1 if the operating system is Android, Returns 0 if it's not

Example

see "IsMSDOS()     --> " + ismsdos()     + nl
see "IsWindows()   --> " + iswindows()   + nl
see "IsWindows64() --> " + iswindows64() + nl
see "IsUnix()      --> " + isunix()      + nl
see "IsMacOSX()    --> " + ismacosx()    + nl
see "IsLinux()     --> " + islinux()     + nl
see "IsFreeBSD()   --> " + isfreebsd()   + nl
see "IsAndroid()   --> " + isandroid()   + nl

Output:

IsMSDOS()     --> 0
IsWindows()   --> 1
IsWindows64() --> 0
IsUnix()      --> 0
IsMacOSX()    --> 0
IsLinux()     --> 0
IsFreeBSD()   --> 0
IsAndroid()   --> 0

Windowsnl() Function

We can get the windows new line string using the Windowsnl() function.

Syntax:

WindowsNL() ---> Returns a string contains CR+LF = CHAR(13) + CHAR(10)

Example:

cStr = read("input.txt")

if iswindows()
        cStr = substr(cStr,windowsnl(),nl)
ok

aList = str2list(cStr)
# to do - list items processing using "for in"
cStr = list2str(aList)

if iswindows()
        cStr = substr(cStr,nl,windowsnl())
ok

write("ouput.txt",cStr)

Get Command Line Arguments

We can get the command line arguments passed to the ring script using the sysargv variable.

The sysargv variable is a list contains the command line parameters.

Example

see copy("=",30) + nl
see "Command Line Parameters" + nl
see "Size : " + len(sysargv) + nl
see sysargv
see copy("=",30) + nl
if len(sysargv) < 4 return ok
nStart = sysargv[3]
nEnd = sysargv[4]
for x = nStart to nEnd
        see x + nl
next

Output

b:\mahmoud\apps\ring>ring tests\syspara.ring 1 10
==============================
Command Line Parameters
Size : 4
ring
tests\syspara.ring
1
10
==============================
1
2
3
4
5
6
7
8
9
10

Get Active Source File Name

We can get the active source file name (*.ring) using the filename() function

Syntax:

filename() ---> String contains the active source file name.

Example:

see "Active Source File Name : " + filename() + nl

Output:

Active Source File Name : tests\filename.ring

Example:

if sysargv[2] = filename()
        see "I'm the main program file!" + nl
        # we can run tests here!
else
        see "I'm a sub file in a program" + nl
ok

CurrentDir() Function

Return the path of the current directory

Syntax:

CurrenDir() ---> String contains the path of the currect directory

ExeFileName() Function

Return the Ring executable file name

Syntax:

exefilename() ---> String contains the Ring executable file name

ChDir() Function

Change the current directory

Syntax:

ChDir(cNewPath)

ExeFolder() Function

Return the Ring executable file path

Syntax:

exefolder() ---> String contains the Ring executable path