Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Advanced isomorphic asynchronous spawn function

License

NotificationsYou must be signed in to change notification settings

ksxnodemodules/advanced-spawn-async

Repository files navigation

Advanced isomorphic asynchronous spawn function

Requirements

  • Node.js ≥ 8.9.0

Usage

Basic Usage

Usage without customspawn function (i.e. Use built-inchild_process.spawn).

importspawnfrom'advanced-spawn-async'const{  process,// ChildProcess  onclose,// Promise<{ command, args, options, stdout, stderr, output, status, signal, process }>  onexit// Promise<{ command, args, options, stdout, stderr, output, status, signal, process }>}=spawn('node')process.stdin.write('console.info("stdout")\n')process.stdin.write('console.error("stderr")\n')process.stdin.end('require("process").exit(0)\n')onclose.then(({ stdout, stderr, output})=>{console.log('CLOSE',{ stdout, stderr, output})})onexit.then(({ stdout, stderr, output})=>{console.log('EXIT',{ stdout, stderr, output})})

Sample Output:

EXIT{stdout:'stdout\n',stderr:'stderr\n',output:'stdout\nstderr\n'}CLOSE{stdout:'stdout\n',stderr:'stderr\n',output:'stdout\nstderr\n'}

Custom Spawn Function

User provide custom spawn function.

import{core}from'advanced-spawn-async'importspawnfrom'cross-spawn'const{ process, onclose, onexit}=core(spawn,'node')// The rest is like the above example

Provide Arguments and Options

importspawnfrom'advanced-spawn-async'const{ onclose}=spawn('echo',['hello'],{stdio:'inherit',event:'close'})onclose.then(status=>console.log({status}))

Non-Zero Status Code

When process returns non-zero code.

importspawnfrom'advanced-spawn-async'const{ process, onclose}=spawn('node',[],{event:'close'})process.stdin.end('process.exit(123)\n')onclose.catch(error=>console.log(error.info))

License

MIT ©Hoàng Văn Khải

Sponsor this project

    Packages

    No packages published

    Contributors4

    •  
    •  
    •  
    •  

    [8]ページ先頭

    ©2009-2025 Movatter.jp