This function executes any command on the Linux system console.
We cannot stress enough that it is very easy to slow down or even completely stop the PClient
misusing this command, it is even possible to destroy almost all data on the device.
But we also know that it can be very useful in certain situations, e.g. to be able to change the
boot logo on a device at runtime.
Prototype:
var ret = runSystemCommand(string command, bool
waitForFinished, bool returnCommandOutput);
Parameters:
·
command: A string with the command to execute
·
waitForFinished: Optional bool flag. If set to true (which is also default if the parameter is
not set), PClient main loop waits until the command has finished. If set to false, the
function will return immediately but the caller will not know the final result of the command
·
returnCommandOutput: If this flag is set to true, this function will return the complete
console output of the executed command instead of the return value. This parameter is
also optional, if not set, the default value is false. Note: If set to true, waitForFinished also
needs to be true.
Return values:
·
true if the command executed successfully while returnCommandOutput was set to false
or not set
·
A string containing the complete output of the executed command if
returnCommandOutput was set to true
·
If anything fails, an exception is thrown and the execution of the whole script file is
interrupted at the line of the system call. Surround with try/catch block for error handling.
Good example:
var ret = runSystemCommand("top -n 1", true, true);
Bad example:
var ret = runSystemCommand("top", true, true);
Why is it bad? The example will never return because top will keep running, thus the
JavaScript file will never finish.
Good example:
var ret = runSystemCommand("rm -rf /opt/data/own_data", true,
false);
Bad example:
var ret = runSystemCommand("rm -rf /opt/*", true, false);