1. Home
  2. Docs
  3. Manual
  4. Playbook
  5. Command list
  6. BigScriptCommand component

BigScriptCommand component

Used to execute a script file or more complex multiline scripts. Compared to RemoteCommand, the latter can only execute one command, while the former can execute multiple complex commands including loops, conditional statements, etc.
Because it is executed asynchronously, in order to facilitate collaboration with async/await, a JS interface with the same name but lowercase initial is encapsulated. The specific source code is as follows: https://github.com/aoyiduo/woterm/blob/main/woterm/js/async.js
Its reference example:

The core code is as follows:

import BigScriptCommand 1.0

BigScriptCommand {
   id: remote

TextArea {
   id: cmd
   Component.onCompleted: {
       cmd.append("#!/usr/bin/env bash")
       cmd.append("df -h")
       cmd.append("ps -ef")
       cmd.append("ping -c 3")
       cmd.append("ls woterm")
       cmd.append("if [ $? -eq 0 ]; then")
       cmd.append("  echo \"yes, it is ok\"")
       cmd.append("  echo \"Sorry, it is bad\"")
    Playbook.log("script start.")
    remote.hosts = hosts.text.split(',')
    yield bigScriptCommand(remote, cmd.text).catch(function(){})
    Playbook.log("script finish.")

The Property list is as follows:
QString script:[readable / writable],Read or set script content.

The list of functions is as follows:

  • bool loadFromFile(const QString& fileName);
    The script content is loaded from a file.
    >>fileName: The absolute path of the local file format.
  • bool saveToFile(const QString& fileName);
    Save the currently executing script to a file.
    >>fileName: The absolute path of the local file format.