34.1.1 • Published 2 years ago

await-shell v34.1.1

Weekly downloads
8
License
MIT
Repository
-
Last release
2 years ago

await-shell

Library for calling POSIX-style shell commands cross-platform. Automatically translates commands for Windows support out of the box.

shell.run() returns a Promise that will resolve or reject to an object containing process information of type SpawnResult:

export interface SpawnResult {
  code: number | null;
  stdout: string;
  stderr: string;
}

Pattern

/**
 * Create a new process where shells will run.
 */
const shell = createShell();

/**
 * Read the exit code, stdout, and stderr from shell.run().
 * 
 * Note: POSIX-like syntax works on Windows! See "Specification" below.
 */
const { code, stdout, stderr } = await shell.run("cp -rf src dest && yarn --cwd dest some-command");

/**
 * Run sequential commands.
 */
await shell.run(
  "cd dir && yarn do_stuff",
  "cd otherDir && yarn do_stuff"
);

Override per-platform

You can override the command to run per-platform in shell.run(...).

const shell = createShell();

/**
 * All process.platform types are supported, i.e. "win32" and "darwin".
 * 
 * "posix" matches "linux" and "darwin".
 */ 
const { code, stdout, stderr } = await shell.run({
  win32: "...",
  posix: "..."
});

Custom options

You can pass custom spawn options to createShell({ ... }).

/**
 * Disable logging of commands and pass custom spawn options. 
 */
const customShell = createShell({
  log: false,
  // Custom process.spawn() options.
  stdio: 'inherit',
  // ...
});

Specification

This section explains how shell command strings (like "cd dir/") are supported on Windows, as well as translations for specific commands.

Shell support

POSIXWindows
DetachedNot detached
my-cmd [...args]cmd.exe /d /s /c my-cmd [...args]

Specific commands

POSIXWindows
cp -rf [src] dest]xcopy /E /S /G /Q /Y [src] [dest]
pkill [pid]taskkill /T /F /pid [pid]
ln [link] [target]mklink [link] [target]

Footnotes

Quotes on Windows

You should use single quotes in your strings if possible for interoperability with Windows.

const { code, stdout, stderr } = await shell.run("my-cmd 'a string'");
34.1.0

2 years ago

34.1.1

2 years ago

32.0.0

2 years ago

31.0.0

2 years ago

30.0.0

2 years ago

34.0.1

2 years ago

34.0.2

2 years ago

34.0.7

2 years ago

34.0.8

2 years ago

34.0.5

2 years ago

34.0.6

2 years ago

34.0.3

2 years ago

34.0.4

2 years ago

33.0.0

2 years ago

19.0.1

2 years ago

19.0.0

2 years ago

19.2.0

2 years ago

10.0.0

2 years ago

23.0.0

2 years ago

22.0.0

2 years ago

8.4.0

2 years ago

2.6.0

2 years ago

26.1.0

2 years ago

18.0.0

2 years ago

7.3.0

2 years ago

7.1.0

2 years ago

3.2.0

2 years ago

3.0.1

2 years ago

25.1.0

2 years ago

21.0.0

2 years ago

8.1.0

2 years ago

8.3.0

2 years ago

3.0.0

2 years ago

20.0.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.2

2 years ago

16.1.0

2 years ago

11.0.0

2 years ago

29.0.0

2 years ago

19.1.0

2 years ago

19.3.0

2 years ago

15.0.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

2.5.0

2 years ago

8.5.0

2 years ago

2.7.0

2 years ago

26.2.0

2 years ago

13.0.2

2 years ago

14.0.0

2 years ago

14.0.1

2 years ago

13.0.0

2 years ago

7.0.0

2 years ago

7.4.0

2 years ago

7.2.0

2 years ago

3.1.0

2 years ago

29.0.1-0

2 years ago

2.4.7

2 years ago

8.0.0

2 years ago

2.4.6

2 years ago

25.0.0

2 years ago

2.4.9

2 years ago

2.4.8

2 years ago

17.0.0

2 years ago

4.1.0

2 years ago

9.0.1

2 years ago

16.0.0

2 years ago

9.0.0

2 years ago

24.0.0

2 years ago

11.1.0

2 years ago

2.3.2

3 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.6

4 years ago

2.1.8

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.5

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.31.1

4 years ago

1.31.0

4 years ago

1.30.0

4 years ago

1.29.0

4 years ago

1.28.0

4 years ago

1.27.0

4 years ago

1.26.0

4 years ago

1.25.0

4 years ago