Tuesday, March 22, 2011

SHELL and EXEC in Gambas 2

Introductions:
I really believed that it will never be the same style again (period).
Yes geek, VB6 will set you freely programming on your desktop but that could not happen anymore in Gambas2 .Why is it brother?well, from time to time there should be a cautions on your coding before you can compile it.Unlike VB6 as long as your syntax is correct there will be a possibilities of outputs.While ,in Gambas you have to secure first each environment /path so that you can link it in a compilations, either you make some scripts,patches or have the careful installation steps by steps.But it doesn't mean Gambas2 will be forsaken,the hardest thought you need to code it the hard core your application program will be.

Since , we have the pros and cons of Gambas2 programming , we'll try to code it what this gambas2 is all about-a hard core programming -systems program management as I would express it. Some built in functions of Gambas2 which are challenging to learn are SHELL and EXEC.

Actually SHELL and EXEC are functions that seems to be the mediator , you have the GUI on top and kernel at the bottom for a programmer to work on smoothly linux platform and want to apply GUI these two functions will be on the rescue-believe me.

So basically SHELL and EXEC


Objectives:
1) Understand the SHELL and EXEC format
2) Understand the SHELL and EXEC syntax
3) Create a program that will SHELL and EXEC
4) Apply SHELL and EXEC in Gambas2 scripting

Methodology:
1) Declare a variable type of data as process
2) Declare a variable as string
3) Assign one variable to be the value of EXEC and Shell process
4) WRITE the process
5) READ the process
6) Split the stringed process
7) Display the parse from an split process

So here is how we use and differentiate the code..
SHELL
DIM sOutPut as String
DIM portOne as String[]

SHELL = " gphoto2 --auto-detect " TO sOutPut
splitString = Split(sOutPut,"\n","")
txtOut1.text =splitString[0]
txtOut2.text =splitString[1]

PortOne= Split(splitString[1],"")

txtOut3.text=PortOne[1]

EXEC
DIM sOutPut as String
DIM portOne as String[]

EXEC [" gphoto2"," --auto-detect "] TO sOutPut
splitString = Split(sOutPut,"\n","")
txtOut1.text =splitString[0]
txtOut2.text =splitString[1]

PortOne= Split(splitString[1],"")

txtOut3.text=PortOne[1]


Remarks:

(1)It is obvious that before anything else in programming Gambas2, you need to
familiarize process management(SHELL & EXEC)
(2)Note:
SHELL function is most likely preferred using a pipe in CLI instead of EXEC
;see for example (ie0:
running a command " ls -l" can be used to both but " ls -l | grep RoBook "will function fine in using SHELL

EXEC ["ls","-l","|","grep","RoBook"] is not proper
SHELL " ls -l | grep RoBook " is considered ok

(3) During process EXEC is much faster than SHELL function (try it..)

Conclusions:
Gambas2 is absolutely good.