This class is used to create operating system processes.
1 Running a process
In Javascript, we can use ProcessBuilder to call external commands easily. In the following example we see how an external ls command (using bash), and display the output.
Copy
<script> var pb = new Ax.lang.ProcessBuilder(); var status = pb.directory('/tmp').command('/bin/bash', '-c', 'ls -l'); if (status == 0) console.log(pb.getStdOut()); else console.log(pb.getStdErr()); return status; </script>
drwx------ 3 jet wheel 96 Dec 20 11:54 com.apple.launchd.hJTk1aPK5y
drwx------ 3 jet wheel 96 Dec 20 11:54 com.apple.launchd.ywxrIg6Iwg
2 Non blocking process
The process.getInputStream is “blocking” so it will block main thread until process completed. In the case we want to run with a timeout to avoid a long running process hangs the script application you can use a timout value.
To set a timeout use setTimeout(int second)
in process builder object.