-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ChildProcess, SpawnOptions } from 'child_process'; | ||
|
||
interface ExtendOptions extends SpawnOptions { | ||
json?: boolean; | ||
} | ||
|
||
interface ResolvedSubprocess extends Omit<ChildProcess, 'stdout' | 'stderr'> { | ||
stdout: string; | ||
stderr: string; | ||
} | ||
|
||
interface SubprocessPromise extends Promise<ResolvedSubprocess>, ChildProcess {} | ||
|
||
declare function extend(defaults?: ExtendOptions): (input: string, args?: string[] | ExtendOptions, options?: ExtendOptions) => SubprocessPromise; | ||
|
||
declare const $: ReturnType<typeof extend> & { | ||
extend: typeof extend; | ||
json: ReturnType<typeof extend>; | ||
}; | ||
|
||
export = $; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import $ from '..' | ||
|
||
/* basic */ | ||
|
||
const promise = $('curl https://www.youtube.com/watch?v=6xKWiCMKKJg') | ||
|
||
// at this point it's a child_process instance | ||
promise.kill() | ||
promise.ref() | ||
promise.unref() | ||
|
||
const result = await promise | ||
|
||
// after that stdout/stderr are available as string values | ||
|
||
console.log(result.stdout) | ||
console.log(result.stderr) | ||
|
||
console.log(result.connected) | ||
console.log(result.signalCode) | ||
console.log(result.exitCode) | ||
console.log(result.killed) | ||
console.log(result.spawnfile) | ||
console.log(result.spawnargs) | ||
console.log(result.pid) | ||
console.log(result.stdin) | ||
console.log(result.stdout) | ||
console.log(result.stderr) | ||
console.log(result.stdin) |