Class Reference process

Executes software and scripts outside the LayoutEditor. More...

Member

int execute(string command,stringList arguments)
string executeTcl(string command)
bool externalTool(string path,string name,stringList parameter,string callback,bool triggerOnOutput=false)
stringList getCommandlineParameter()
string getEnv(string parameter)
bool isLinux()
bool isMac()
bool isRunning(string toolName)
bool isWindows()
int setEnv(string parameter,string value)
bool openBrowser(string url)
string startPythonScript(string filename,stringList args=stringList())
string startTclScript(string filename)
void terminate(string toolName)
string toolData()
string toolResult()
string trigger()
bool startDetached(string command,stringList arguments)

Detailed Description

The process class contains several commands to control external software tools. The started tool can run independend of the LayoutEditor, or the execution of the macro can wait on the result of the external tool. Also an interface to start external LayoutScript is supported.

Also reading and writing environment variable can be done with this class.

Member Function Documentation


static int process::execute(string command,stringList arguments)

command is executed with the given arguments. It waits until command terminates and the exit code is returned. If arguments is a string it is split on spaces to a stringList.


static string process::executeTcl(string command)

A TCL command is executed and its output returned. (introduced with release 20200214)

string s=process::executeTcl("puts $application\n");

static bool process::externalTool(string path,string name,stringList parameter,string callback,bool triggerOnOutput=false)

searches and executes the tool name with parameter. path is a hint where to find the tool. callback macro is called as soon the tool finished. The method will return immediately and does not wait until the started tool terminated. true is return, if the tool was started successfully.

If the optional parameter triggerOnOutput is set to true, the callback macro will be regulary called when the executed tool write to the output. (option introduced with release 20190919)

#!/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");
 }
}

static stringList process::getCommandlineParameter()

Returns: the commandline parameter the LayoutEditor was started with.


static string process::getEnv(string parameter)

Returns: the environment variable parameter

 layout->showMessage("your home path",process::getEnv("HOME"));

static bool process::isLinux()

Returns: true if the LayoutEditor was created for Linux


static bool process::isMac()

Returns: true if the LayoutEditor was created for Mac OSX


static bool process::isRunning(string toolName)

Returns: true if the external process started before with the externalTool command is still running. toolName must be identical with the name used when calling the process. (introduced with release 20190923)


static bool process::isWindows()

Returns: true if the LayoutEditor was created for Microsoft Windows


static int process::setEnv(string parameter,string value)

set the environment variable parameter to value


static bool process::openBrowser(string url)

opens a browser with the url.

#!/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;
}

static string process::startPythonScript(string filename,stringList args=stringList())

Starts a Python script with parameter args.


static string process::startTclScript(string filename)

Starts a TCL script.


static void process::terminate(string toolName)

Terminates the external process started before with the externalTool command. toolName must be identical with the name used when calling the process. (introduced with release 20190923)


static string process::toolData()

Returns: the new output text to the command line since the last callback call, if the macro is a callback of an externalTool command (see above). In all other cases an empty string is returned. (introduced with release 20190919)


static string process::toolResult()

Returns: the output to the command line, if the macro is a callback of an externalTool command (see above). 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;
}

static string process::trigger()

Returns: the event triggering the macro execution, if the macro is a callback of an externalTool command (see above). Possible values are output and completed. (introduced with release 20190919)

Obsolete Members


static bool process::startDetached(string command,stringList arguments)

command is executed with arguments. It returns true, if the program launch was successful. If arguments is a string it is split on spaces to a stringList. There is no control on the started process. Use the externalTool feature , in case the process needs to be controled.