• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ShellCmdResult
2
3The **ShellCmdResult** module provides the shell command execution result.
4
5> **NOTE**
6>
7> 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.
8> The APIs provided by this module can be used only in the test framework.
9
10## Modules to Import
11
12```ts
13import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
14```
15
16## Attributes
17
18**System capability**: SystemCapability.Ability.AbilityRuntime.Core
19
20| Name     | Type  | Readable| Writable| Description                                                        |
21| --------- | ------ | ---- | ---- | ------------------------------------------------------------ |
22| stdResult | string | Yes  | Yes  | Standard output content.|
23| exitCode  | number | Yes  | Yes  | Result code.|
24
25## Usage
26
27The result is obtained by calling [executeShellCommand](js-apis-inner-application-abilityDelegator.md#executeshellcommand) in **abilityDelegator**.
28
29**Example**
30```ts
31import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
32import { BusinessError } from '@ohos.base';
33
34let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator;
35let cmd = 'cmd';
36
37abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
38abilityDelegator.executeShellCommand(cmd, (error: BusinessError, data) => {
39    if (error) {
40        console.error(`executeShellCommand fail, error: ${JSON.stringify(error)}`);
41    } else {
42        console.log(`executeShellCommand success, data: ${JSON.stringify(data)}`);
43    }
44});
45```
46