@utilx/process
v0.0.9
Published
Downloads
3
Readme
process-utils
import r from "process-utils"
async function main(){
const { code, stdout, stderr } = await r("echo hi")
if (code === 0) console.log(stdout)
r$("echo hi")
r$.ctx.code = 0
console.log(ctx.pid, ctx.status)
const p = await ra("echo hi")
r("echo hi")
await npm.install.save_dev("fs-extra", "numpy")
npm.install.save_dev$("fs-extra", "numpy")
r$("apt install ")
r$("apt install vim emacs -y")
r$("brew install markdown")
r$("yum install vim -y")
const { error, pid, status, code, signal } = await npm.install.save("fs-extra")
const { error, pid. status, code, signal } = npm.install.save$("fs-extra")
const npm_res = await npm.install("fs-extra")
npm.install.save$("fs-extra").pipe( awk.check$("") )
const p1 = await npm.install.save$("fs-extra").throwError()
npm.install.save("fs-extra")
console.log(npm_res.pid, npm_res.status)
apt.install.yes$("vim")
console.log(ctx.pid, ctx.status)
await apt.install("vim")
console.log("visualized")
apt.install_("vim")
apt.install("vim").toString_() // promise design
apt.install("vim") // promise design
}
关于result的设计,我们默认需要用户写防御式代码
const result = processinstance.get()
"code" in result && console.log(result.code)
if ("code" in result) {
console.log(result.code, result.signal)
}
另外一种写法是,用户很确定这里不会有问题,否则程序会以ERROR方式中断
const result = processinstance.getOrThrow() // no Error
console.log(result.code, result.signal)