Creates a SystemProcedure of a command shell (ie. “sh”, “su” if root or “busybox” if installed) which can be reused throughout the program.
Example - Basic
function OnStart()
{
lay = app.CreateLayout( "linear" );
txt = app.CreateText( "", 1, 1, "Log,Monospace,autoscale" );
lay.AddChild( txt );
app.AddLayout( lay );
sys = app.CreateSysProc( "sh" );
sys.Out( "netstat\n" );
sys.SetOnInput( sys_OnInput );
sys.SetOnError( sys_OnError );
sys.Out( "netstoat\n" );
}
function sys_OnInput( msg )
{
txt.Log( msg );
}
function sys_OnError( msg )
{
txt.Log( msg );
}
Example - Colored
function OnStart()
{
lay = app.CreateLayout( "linear" );
scr = app.CreateScroller( 1, 1, "horizontal" );
lay.AddChild( scr );
txt = app.CreateText( "", 1, -1, "monospace,log" );
txt.SetTextSize( 8 );
txt.SetLog( 1000 );
scr.AddChild( txt );
app.AddLayout( lay );
sys = app.CreateSysProc( "sh" );
sys.SetOnInput( sys_OnInput );
sys.SetOnError( sys_OnError );
Exec( "netstat\n" );
Exec( "ls -al /sdcard/ | grep D >&2\n" );
}
function Exec( cmd )
{
sys.Out( cmd );
txt.Log( cmd, "green" );
scr.ScrollTo( 0, txt.GetHeight() );
}
function sys_OnInput( msg )
{
txt.Log( msg );
scr.ScrollTo( 0, txt.GetHeight() );
}
function sys_OnError( msg )
{
txt.Log( msg, "red" );
scr.ScrollTo( 0, txt.GetHeight() );
}
Methods
The following methods are available on the SysProc object:
string
number: integer
string: path to file or folder ( “/absolute/...” or “relative/...” )
string: program name: “sh” or “su” or “busybox”
string: comma “,” separated: “combine” or
“builder”
string: comma “,” separated: “nowait”
list: boolean,char,byte,short,int,long,float,double,String,CharSequence,...
sys.Err
Read data from stderr
sys.GetType
Returns the control class name.
sys.In
Read data from stdin
sys.MethodAllows access to other functions defined on the object in Java via reflection.
Note: This function is a premium feature. Please consider subscribing to Premium to use this feature and support DroidScript in its further development.
sys.Out
Writes a command to stdout. A trailing linebreak will execute it.
sys.ReadFileAsByte
Returns the first byte of a file.
sys.SetOnError
Define a callback function which is called when something was written to stderr
sys.SetOnInput
Define a callback function which is called when something was written to stdout
sys.WriteToFile
Write a binary string to a file.