Execute External Programs
abstract
Sahi allows calling external programs via _execute or by calling Java directly
_execute
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.0.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | Android | iOS | SAP
_execute($cmd[, $isSync[, $timeout]])
Arguments
$cmd | string | Command to be executed. Normally this will be a command that can be run on the system's commandline |
$isSync | boolean optional | If true, returns only on completion of cmd. If false, returns immediately while cmd is run in background |
$timeout | integer optional | If timeout is specified and if isSync is true, the function will return after timeout milliseconds if cmd has not finished till then. cmd will continue to run in background |
Returns
string | command output |
Sahi Pro Flowcharts Action :Execute
Details
_execute allows calling batch files, shell scripts or regular commands from Sahi script.
_execute allows calling batch files, shell scripts or regular commands from Sahi script.
_execute("C:\\sendemail.bat"); // runs C:\sendemail.bat and returns immediately while sendmail runs in the background
_execute("C:\\sendemail.bat", true); // runs C:\sendemail.bat and waits till sendmail finishes
// runs C:\sendemail.bat and returns after 2 seconds if sendmail has not completed by then.
_execute("C:\\sendemail.bat", true, 2000);
// if _execute("C:\\sendemail.bat"); does not work, on Windows, try:
_execute("cmd /C C:\\sendemail.bat");
// On Linux and Mac use forward slashes as filepath separator
// Make sure that the shell script has necessary permissions
_execute("/home/user1/bin/sendemail.sh");
// or
_execute("sh /home/user1/bin/sendemail.sh");
warning
Since _execute delegates the command to the operating system's command shell,
make sure that you use the correct path separators (backslash \ for windows and / for Linux/Mac)
and have the correct permissions.