Comments (10)
@revelt Either execa(commandApp, commandAttributes, {stdio: 'inherit'})
or use the --color
flag to force colors.
from execa.
I often want stdio: 'inherit'
behaviour (which is normally only an option with cp.spawn()
or execa.spawn()
, I think) but with the simple promise-returning API of execa()
.
The stdio: 'inherit'
option lets you watch logs coming from the child process live and incrementally (and in colour!), which is what I want 50% of the time. But it means I have to use spawn, and therefore have to manually hook up event listeners to handle the child process ending or erroring.
I often find myself writing a wrapper like this:
function run(file, args, options = {}) {
return new Promise((resolve, reject) => {
const child = execa.spawn.call(
null, file, args, Object.assign({ stdio: 'inherit' }, options)
);
child.on('error', reject);
child.on('exit', code => {
if (code === 0) resolve();
else reject();
});
});
}
It would be great if execa()
could introduce an option like this.
Even better would be if there was some nice way to visually distinguish the child logs as being from the child process, like prefixing each line with >
or something (but still retaining ANSI colour codes in the child logs).
EDIT
Just thought of another way of approaching this, maybe the solution is simply to add a new promise-returning method to spawned child process objects:
const child = execa.spawn(...);
const {stdio, stderr} = await child.exited();
I guess this would give the most flexibility, as you still get access to a ChildProcess
instance (in case you need to send a signal to it, or something) but you also get the convenience of a promise-based way to monitor its completion.
Maybe the .exited()
method (not sure about the name) could even take an argument to set the expected exit code, e.g. .exited(0)
would mean any non-zero exit code causes a rejection.
from execa.
@callumlocke I really like the idea! I've had similar needs. Would you mind moving this into a new issue?
from execa.
IPC support, like in child_process.spawn
's options.stdio
would be awesome.
child-process-promise seems to do a good job of this, because it's a wrapper and supports the same options as the thing it's trying to improve, is that why you had chosen not to go that route?
from execa.
@zealoushacker Should already be supported, since we use child_process.spawn()
internally, but needs to be tested and documented.
from execa.
Automatic handling of timeout by execa for executed processes would be nice. You define a max running time of e.g. 15000ms and the executed process has to finish within this time limit or will be killed. This is very useful for any application which has to fulfill QoS criterias.
from execa.
@tpetry execa
already has a timeout
option:
execa(file, [arguments], [options])
Same options as
child_process.execFile
.
from execa.
My fault, you're right. Didn't look up the options because i expected the same options as child_process.spawn
from execa.
Is there a way to make it so that the output of the commands run via execa
is coloured in the terminal?
I'm running it this way:
execa(commandApp, commandAttributes).stdout.pipe(process.stdout)
but everything in the terminal (tested on both hyper.js and iTerm) is black and white.
To give some context, I'm using execa
in fol to allow people to input a folder name, then let them pick a subfolder from a list, then place that choice into user's chosen terminal command. I need this, for example, to call gulp with a flag and a name of a subfolder, like gulp -t vip_template_64
. That subfolder name varies, it's the different template I pick each time.
I got it wired and working, just the stdout
output is uncoloured.
Thanks in advance.
from execa.
@sindresorhus it worked! thanks a lot.
from execa.
Related Issues (20)
- Not able to inject environment variables HOT 3
- Node.js engine version in package.json is not up-to-date HOT 6
- Document CLI utilities
- Subprocess is considered as failed exit when using `process.kill` on windows only HOT 6
- Graceful termination HOT 1
- Document idiomatic ternary interpolation pattern? HOT 2
- TypeError: The "eventTargets" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal HOT 7
- Feature request: Possibility to use a custom verbose log format? HOT 5
- stdout/stderr with 'inherit' + transform should not capture output HOT 2
- Unable to extend env when `ProcessEnv` has been manipulated HOT 7
- Typescript: Verbose option type mismatch? HOT 2
- Memory Leak of pipe HOT 3
- `parseCommandString()` splits at whitespace inside quotes HOT 3
- Timeout / cancel stuck process HOT 4
- The command cannot be executed HOT 1
- Intl needed for v. 9 HOT 10
- Error: Premature close HOT 23
- Small package alternative to Execa HOT 9
- Add a link to `nano-spawn`
- How to get both live and programmatic output? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from execa.