Executes software and scripts outside the LayoutEditor. More...
process is a static hub for starting programs and scripts outside the LayoutEditor. There is no object to construct: call process::execute, process::externalTool, or process::getEnv. execute runs a command, waits until it finishes, and returns the exit code. externalTool starts a tool and returns at once; a callback macro runs when the tool finishes, or on output if triggerOnOutput is true. isRunning and terminate use the same name as externalTool. startPythonScript and startTclScript run scripts; executeTcl runs one Tcl command. getEnv and setEnv read and write environment variables. isLinux, isMac, and isWindows report the build of the LayoutEditor. getCommandlineParameter returns the arguments the LayoutEditor was started with as a stringList.
Example:
stringList args;
args.append("--help");
int code = process::execute("ls", args);
string home = process::getEnv("HOME");
if (process::isLinux())
process::openBrowser("https://layouteditor.org");
Runs command with arguments and waits until it terminates. If arguments is a string it is split on spaces to a stringList.
| Parameter: | |
|---|---|
| command | executable to run |
| arguments | command-line arguments |
Returns: the exit code of command.
Runs a Tcl command and returns its output.
Returns: the Tcl output as a string.
string s=process::executeTcl("puts $application\n");
Searches for and starts tool name with parameter. path is a hint where to find the tool. The callback macro is called as soon as the tool finishes. This method returns immediately and does not wait until the tool terminates. true is returned if the tool was started successfully.
If the optional triggerOnOutput is true, the callback macro is also called regularly when the tool writes output.
| Parameter: | |
|---|---|
| path | directory hint used to find the tool |
| name | tool name, also used later with isRunning and terminate |
| parameter | command-line arguments |
| callback | macro file called when the tool finishes (or on output) |
| triggerOnOutput | if true, call the callback on output as well |
Returns: true if the tool was started, otherwise false.
#!/usr/bin/layout
#name=start bash script
#help=start bash script with callback macro
int main(){
file f;
string path=f.currentPath();
stringList sl;
sl.append(path+"/script");
sl.append(layout->filename);
if (process::externalTool("/bin","bash",sl,path+"/callback.layout")) {
layout->showStatus("bash script started");
} else {
layout->showStatus("failed to start bash script");
}
}
Returns: the command-line parameters the LayoutEditor was started with.
Returns: the environment variable parameter.
layout->showMessage("your home path",process::getEnv("HOME"));
Returns: true if this LayoutEditor was built for Linux.
Returns: true if this LayoutEditor was built for Mac OS X.
Returns: true if the external process started earlier with externalTool is still running. toolName must be identical with the name used when starting the process.
Returns: true if this LayoutEditor was built for Microsoft Windows.
Sets the environment variable parameter to value.
Returns: the result of the underlying set operation.
| Parameter: | |
|---|---|
| parameter | parameter |
| value | value |
Opens a browser with url.
Returns: true if a browser was started, otherwise false.
#!/usr/bin/layout
#name=open browser
#help=open browser with the LayoutEditor docmentation
int main(){
if (!process::openBrowser("https://layouteditor.org")){
layout->showStatus("browser not found");
}
return 0;
}
Starts a Python script filename with argument list args.
| Parameter: | |
|---|---|
| filename | path of the Python script |
| args | arguments passed to the script |
Returns: the script output as a string.
Starts a Tcl script filename.
Returns: the script output as a string.
Terminates the external process started earlier with externalTool. toolName must be identical with the name used when starting the process.
Returns: the new command-line output since the last callback, if this macro is a callback of externalTool. In all other cases an empty string is returned.
Returns: the command-line output if this macro is a callback of externalTool. In all other cases an empty string is returned.
#!/usr/bin/layout
#name=callback macro
#help=callback macro to show output in the TextEditor
int main(){
string s=process::toolResult();
if (s.size()>1){
textEdit *te=project::getCentralTextEditor();
if (te->drawing->text()!="") {
te->newFile();
te->setFile(te->countFiles()-1);
}
te->setText(s);
te->drawing->title="Command Line Output";
te->drawing->setModifySaved();
}
return 0;
}
Returns: the event that started this macro, if this macro is a callback of externalTool. Possible values are output and completed.
Runs command with arguments. Returns true if the program launch was successful. If arguments is a string it is split on spaces to a stringList. There is no further control of the started process. Use externalTool if the process needs to be controlled.
| Parameter: | |
|---|---|
| command | executable to run |
| arguments | command-line arguments |
Returns: true if the program was launched, otherwise false.