Computer Science Canada

Sys.Exec and making shell style programs

Author:  aldreneo [ Tue May 02, 2006 8:51 pm ]
Post subject:  Sys.Exec and making shell style programs

Sys.Exec and making shell style programs

Quote:

The Turing Help
Syntax: Sys.Exec ( command : string ) : boolean

Description: The Sys.Exec function is used to execute an application or more often, open a data file with its associated application. Sys.Exec can be used to launch such programs as the Internet Browser by specifying a URL. Sys.Exec launches the application associated with file's suffix. (In essence, it performs the same operation as if a user double clicked on the file.)

in this we will learn how to make shell(command line) style programs.

First we need a command line style window

    Black background
    White text
    Command line

The code for that is simple we need to make a window with a black background, and white text.
code:

% Open/setup the window
var win : int
win := Window.Open ("position:top;center,graphics:400;200")
% setup the colors
setscreen ("graphics")
color (white)
colorback (black)
cls
% Make the command.com style copyright info
put "Turing Run window [Version 1.0]"
put "(C)Copyright aldreneo 2006."
put ""


Next we need the command line...
In order to be shell style we need to to return to the command line after running a command. In order to do this we will run a proc then inside the proc run it again.

code:

proc cmd
    put ">" .. % The command line text
    get run
    cmd
end cmd


Next we need it to run commands...this is the dirt of things...

in order to run commands we need to use the following...
code:

    if not Sys.Exec (command) then
        put "your error here"
    end if


Now we need to use this code and put it into our command loop using run which we got from the get statement as the command to run.
code:

% The command loop
proc cmd
    var run : string
    put ">" .. % The command line text
    get run
    % Run the command
    if not Sys.Exec (run) then
        put "'", run, "' is not recognized as an internal or external command,operable program or batch file."
    end if
    % Run the loop again
    cmd
end cmd

Now we are missing the cls command...we want this to clear the screen..We will add this right below"get run"
code:

    if run = "cls" then % check if the command is cls
        cls;
        cmd
    end if

now the final code should look like this:
code:

% ----------------------------------|
% The Run command shell             |
% Version: 1.0                      |
% ----------------------------------|


% Open/setup the window
var win : int
win := Window.Open ("position:top;center,graphics:400;200")
setscreen ("graphics")
color (white)
colorback (black)
cls
put "Turing Run window [Version 1.0]"
put "(C)Copyright aldreneo 2006."
put ""

% The command loop
proc cmd
    var run : string
    put ">" .. % The command line text
    get run
    if run = "cls" then % check if the command is cls
        cls;
        cmd
    end if
    % Run the command
    if not Sys.Exec (run) then
        put "'", run, "' is not recognized as an internal or external command,operable program or batch file."
    end if
    % Run the loop again
    cmd
end cmd
cmd


Please tell me if I am missing anything or need anything...this is my first tutorial...thanks.

Author:  aldreneo [ Tue May 02, 2006 8:52 pm ]
Post subject: 

There it is finished...

Please comment on it

Author:  Tony [ Tue May 02, 2006 9:00 pm ]
Post subject: 

just edit the post.. I'll remove redundant replies later


: