Calling a Command

CommandCall API

class CommandCall(config)

Creates a new CommandCall object.

Arguments
Throws

Will throw an error when the first parameter is not an object.

Throws

Will throw an error when an invalid command type is set.

CommandCall.toXML()
Returns

string – The command in xml format.

clOptions()

CL Command Options

Arguments
  • exec (string) – How to run the command. Valid options: cmd, system, or rexx. Default is cmd.

  • error (string) – Determines action when an error is encountered. Valid options are on, off, or fast. Default is fast. Using on will cause the script execution to stop and log a full error report. Using off or fast continues executing the script. The Difference is that fast will log a brief error report and off will not.

  • hex (string) – Whether to output data in hex format. Valid options are on or off. Default is off.

  • before (string) – The CCSID to convert to before the command call.

  • after (string) – The CCSID to convert to after the command call.

shOptions()

QSH and SH Command Options

Arguments
  • rows (string) – Whether to split the output row by row. Valid options are on or off. Default is off.

  • error (string) – Determines action when an error is encountered. Valid options are on, off, or fast. Default is fast. Using on will cause the script execution to stop and log a full error report. Using off or fast continues executing the script. The Difference is that fast will log a brief error report and off will not.

  • hex (string) – Whether to output data in hex format. Valid options are on or off. Default is off.

  • before (string) – The CCSID to convert to before the command call.

  • after (string) – The CCSID to convert to after the command call.

commandCallConfig()

CommandCall Configuration

Arguments
  • command (string) – The command string to run.

  • type (string) – The type of the commmand: cl, qsh, sh. NOTE: qsh type requires XMLSERVICE >= 1.9.8.

  • commandOptions (clOptions|shOptions) – The options for the command.

Example

Call the RTVJOBA CL command

const { Connection, CommandCall } = require('itoolkit');
const { XMLParser } = require('fast-xml-parser');


const connection = new Connection({
  transport: 'ssh',
  transportOptions: { host: 'myhost', username: 'myuser', password: 'mypassword' },
});

const command = new CommandCall({ type: 'cl', command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)' });

connection.add(command);

connection.run((error, xmlOutput) => {
  if (error) {
    throw error;
  }

  const Parser = new XMLParser();
  const result = Parser.parse(xmlOutput);

  console.log(JSON.stringify(result));
});