ExtExec allows you to execute Linux shell commands in the powerful Linux environment provided by the free app called Termux.
Note: This function is a premium feature. Please consider subscribing to Premium to use this feature and support DroidScript in its further development.
The Termux app runs as a service and there's almost no limit to what you can achieve with a full blown Linux machine running on your Android device!
How about installing git, or nodejs or using ssh or gzip.
Try typing 'busybox' at the terminal prompt to see what built-in commands are already available to you.
Enable Termux
To enable termux support you have to install Termux and the Tasker Plugin from PlayStore first.
Then give termux sdcard permissions in the Android settings under apps/termux.
After that create a symbolic link from the tasker plugin folder to your home directory:
mkdir -p .termux /sdcard/termux/scripts
ln -s /sdcard/termux/scripts .termux/tasker
Finally you can run a termux shell script from inside DroidScript:
Example - Open Termux and pass arguments
function OnStart()
{
app.WriteFile( "/sdcard/termux/scripts/hello.sh", "echo Hello $1 and $2" );
var err = app.ExtExec( "termux", "hello.sh", 'World "' + app.GetUser() + '"', "" );
if( err ) app.Alert( "Termux Error:" + err );
}
Example - Execute in Background and retreive output
var itv, lock = "/sdcard/.termuxlock";
var script = `
{ # this is a comment
echo This is a message # prints to stdout
sleep 1 # waits 1 second
echo This is an error 1>&2 # prints to stderr
} 1>/sdcard/out.txt 2>/sdcard/err.txt; # forward stdout and stderr to files
rm ` + lock;
function OnStart()
{
app.WriteFile( "/sdcard/termux/scripts/hello.sh", script );
app.WriteFile( lock, "" );
app.ShowProgress( "Script is running" );
var err = app.ExtExec( "termux", "hello.sh", "", "hide" );
if(err) app.Alert(err);
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
txt = app.CreateText( "", .8, .8, "monospace,multiline,left" );
lay.AddChild( txt );
app.AddLayout( lay );
itv = setInterval( CheckReady, 100 );
}
function CheckReady()
{
if( !app.FileExists( lock ))
{
app.HideProgress();
clearInterval(itv);
var stdout = app.ReadFile( "/sdcard/out.txt" );
var stderr = app.ReadFile( "/sdcard/err.txt" );
var text =
"stdout:\n" + stdout + "\n\n" +
"stderr:\n" + stderr;
txt.SetText( text );
}
}