Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Sys.Exec and making shell style programs
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aldreneo




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
aldreneo




PostPosted: Tue May 02, 2006 8:52 pm   Post subject: (No subject)

There it is finished...

Please comment on it
Tony




PostPosted: Tue May 02, 2006 9:00 pm   Post subject: (No subject)

just edit the post.. I'll remove redundant replies later
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: