ShellCmdResult

The ShellCmdResult module provides the shell command execution result.

NOTE

The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs of this module can be used only in JsUnit.

Modules to Import

import { abilityDelegatorRegistry } from '@kit.TestKit';

Usage

The result is obtained by calling executeShellCommand in abilityDelegator.

Example

import { abilityDelegatorRegistry } from '@kit.TestKit';
import { BusinessError } from '@kit.BasicServicesKit';

let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator;
let cmd = 'cmd';

abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.executeShellCommand(cmd, (error: BusinessError, data) => {
  if (error) {
    console.error(`executeShellCommand fail, error: ${JSON.stringify(error)}`);
  } else {
    console.info(`executeShellCommand success, data: ${JSON.stringify(data)}`);
  }
});

ShellCmdResult

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Type Read-Only Optional Description
stdResult string No No Standard output of the shell command.
exitCode number No No Result code of the shell command.