Git Product home page Git Product logo

child-process-promise's People

Contributors

dbkaplun avatar dgreif avatar gunderson avatar pascalduez avatar patrick-steele-idem avatar sequoia avatar tintypemolly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

child-process-promise's Issues

EMFILE error - can be avoided?

I have a large job which runs Promise.all on a bunch of files, which in turn each refer to a bunch of image files. On these, I call child-process-promise.exec(image processing command). As there's not a good way to estimate the number of images to be processed, I'm frequently running into a EMFILE error:
Error: spawn /bin/sh EMFILE image processing command (exited with error code EMFILE)

Can this be avoided? I'm thinking of how the npm package graceful-fs fixes this problem for fs. Can the same thing be done in child-process-promise?

I have set my number of concurrent files open to 10480 (ulimit -n)

Windows support

It seems when I try to use this on windows I just get the error spawn ENOENT. I am writing a cli tool that is working fine on Linux and Mac, but not on windows.

I am still running a few tests (slowly) but right now it seems like the error is due to this library. Will update if I make more progress.

Edit: Yep, changing to https://www.npmjs.com/package/superspawn fixes the issue.

missing stream output

normal node spawn can get us also stream of data. Is it possible to get a stream from chld-process-promise spawn command ?

thanks

your libary resolve my problem.

Warning: a promise was rejected with a non-error object

Hello!
I'm using Bluebird.js and your package.
I'm facing a little warning which leads to an error for my specific code for error handling.
It seems that when your getting an error in index.js cp.on('close') function, your not creating an Error object but a basic object.

I think you should consider reject promises with real error objects to make this compatible with well known promise library like bluebird or q

Thanks.

Allow maxBuffer option in exec

Currently passing maxBuffer object doesn't do anything, below is how i would do it with default exec (wrapped in promise wrapper)

const data = await exec('aws s3api list-objects --bucket ....', { maxBuffer: 1024 * 10000 })

Tried doing this with child-proccess-promise and doesn't work, but maybe i have the syntax wrong?

How to kill an exec process before it finishes?

If I start an exec process within an asynchronous function like this:

let process = await exec('sleep 3')

and then later attempt to kill that process before it finishes by doing this:

process.kill()

I get the error "TypeError: process.kill is not a function". I am able to kill a process in this manner when using the standard child_process module with callbacks. What would be the correct way to kill an exec process before it has finished using this library?

Thanks

Problem with "dither:diffusion-amount=20%" in spawn

Hello

I am building a small webapp with Firebase to provide e-paper-ready images. To convert images to bitmap i am using a cloud function (node.js) and the Imagemagick Library.

I have the following string in a Node.js Firebase Cloud Function:
await spawn('convert', [tempFilePath, '-resize', displaySize + '^', '-gravity', 'center', '-extent', displaySize, dither, ditherValue, '-define', 'dither:diffusion-amount=20%', '-remap', tempFilePath_Map, '-type', 'Palette', 'BMP3:' + tempFilePathBitmap]);
Which should be equal to this:
convert image.pngl -resize 600x448^ -gravity center -extent 600x448 -dither FloydSteinberg -define dither:diffusion-amount=20% -remap eink-7color.png -type Palette, BMP3:images.bmp

It works very well. But: The following option has no effect:
dither:diffusion-amount=20%

Has it something to do with the %-sign? Do i need to escape it correctly? I think Google is is running ImageMagick 7.0.10-48.
And other guys confirmed that this command should work with this version.

[https://github.com/ImageMagick/ImageMagick/discussions/3023]

Any help is very welcome.

Lukas

Recommend using promisify-child-process instead?

Awhile ago I hurriedly rewrote this library to add some features and released it as promisify-child-process. Aside from impatience with making PRs and waiting for them to get merged, I wanted to:

  • Also promisify execFile and fork
  • Export the sync methods so that it can be a drop-in replacement for child_process
  • Include flow type defs
  • Have a full CI setup with semantic-release

I realize now that I created unfortunate fragmentation in the ecosystem and I should try to merge my code into this project (assuming you wouldn't prefer to deprecate this package in favor of mine).

What do you guys want me to do? The easiest thing would be making a PR that essentially replaces all code in this repo with mine (it would not cause any breaking changes to the API) but that might seem a bit heavy-handed.

node < 4 support PR?

Would you accept a pr which utilizes webpack + babel to expose an es5 version?

Currently the line lower versions of node trip up on lib/index.js:139

var err = {
  code: code,
  message: '`' + commandStr + '` failed with code ' + code,
  childProcess: cp,
  toString() { // <------------- invalid syntax
    return this.message;
  }
};

You could keep the default require pointing to your current entry point, and have webpack output a file es5.js which would allow people to require('child-process-promise/es5').

As for "why?" - my corporate environment runs build servers using node v0.12.14 and so our development environment should run on the same. Getting my co-workers using the command line is hard enough, but if they have to remember to mess with nvm in order to use the few CLI tools I create, that's a hurdle they shouldn't have to deal with.

I appreciate the module regardless!

Kill signal is not checked or logged hiding the actual cause of failure

If a process gets killed (by user or by the os due to reaching memory limit) the resulting error hides the actual cause:

`<command>` failed with code null

Currently in the code the signal is not checked nor logged in the exception making it very hard to track down the actual issue.
image

More info about the case in which code can be null here.

Typescript definitions

Hello!

Are there going to be type definition files for this package in Definitely Typed any time soon? I never expected a library that is downloaded 328667 times per week (at the time of writing) to not have a definition file!

Please consider creating one or writing a more thoroughly detailed documentation page so I can write it myself.

Does not catch 'exit' event from spawn()

For some use cases, you need to catch exit event because close only waits for stdout.
If the application you run using spawn() creates a child process and detaches it with sharing stdout, close event will never fire even if the application is actually terminated. Which means the promise would never be resolved or rejected.

getting a 'failed with code 1'

from this simple test file:

const spawn = require('child-process-promise').spawn

spawn('convert', ['-background none -stroke "rgba(245, 115, 150, 1)" -fill "rgba(245, 115, 150, 0.56)" -font fonts/AbrilFatface-Regular.ttf -pointsize 100 label:"My Text Here!" -trim ( +clone -background "rgba(0, 0, 0, 0.25)" -shadow 80x8+8+10 ) +swap -background none -layers merge +repage shadow_leggings_from_script.png'])

I'm getting this as output:
(node:21968) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ChildProcessError: \convert -background none -stroke "rgba(245, 115, 150, 1)" -fill "rgba(245, 115, 150, 0.56)" -font fonts/AbrilFatface-Regular.ttf -pointsize 100 label:"My Text Here!" -trim ( +clone -background "rgba(0, 0, 0, 0.25)" -shadow 80x8+8+10 ) +swap -background none -layers merge +repage shadow_leggings_from_script.png` failed with code 1`

however if I take the output of the spawn message:
convert -background none -stroke "rgba(245, 115, 150, 1)" -fill "rgba(245, 115, 150, 0.56)" -font fonts/AbrilFatface-Regular.ttf -pointsize 100 label:"My Text Here!" -trim ( +clone -background "rgba(0, 0, 0, 0.25)" -shadow 80x8+8+10 ) +swap -background none -layers merge +repage shadow_leggings_from_script.png

and run this in the console, the command for the imagemagick convert command runs just fine:

shadow_leggings_from_script

I'm suspecting that perhaps the ( in the command line input for the convert command is causing the problem but hoping someone has been able to find a work around or a proper way to escape the parens...I've tried \( and no go

[Enhancement] Consider changing to Bluebird

Just a thought, but would you consider replacing q with bluebird? I keep hearing that it has an order of magnitude better performance, though I have no empirical proof of this myself.

`fs` and `child_process` not found

I've successfully installed the package. When I try to run my app with an import of exec from the package, npm fails to build because it cannot find fs and child_process.

The app is an Angular one and I'm trying to import the package in the main.ts file in the root of the project.

The exact errors:

ERROR in ./node_modules/child-process-promise/lib/index.js
Module not found: Error: Can't resolve 'child_process' in 'my_project\node_modules\child-process-promise\lib'
ERROR in ./node_modules/child-process-promise/lib-es5/index.js
Module not found: Error: Can't resolve 'child_process' in 'my_project\node_modules\child-process-promise\lib-es5'
ERROR in ./node_modules/child-process-promise/node_modules/cross-spawn/index.js
Module not found: Error: Can't resolve 'child_process' in 'my_project\node_modules\child-process-promise\node_modules\cross-spawn'
ERROR in ./node_modules/child-process-promise/node_modules/cross-spawn/lib/parse.js
Module not found: Error: Can't resolve 'fs' in 'my_project\node_modules\child-process-promise\node_modules\cross-spawn\lib'
ERROR in ./node_modules/isexe/index.js
Module not found: Error: Can't resolve 'fs' in 'my_project\node_modules\isexe'
ERROR in ./node_modules/isexe/mode.js
Module not found: Error: Can't resolve 'fs' in 'my_project\node_modules\isexe'
ERROR in ./node_modules/isexe/windows.js
Module not found: Error: Can't resolve 'fs' in 'my_project\node_modules\isexe' 

Module modifies external objects in `options`

script

var spawn = require('child-process-promise').spawn;

var opts = { capture: ['stdout','stderr'] };

function makeSpawnHello(){
  return spawn('echo', ['hello'], opts);
}

var count = 0;

makeSpawnHello()
.then(function(result){
  console.log('output ' + ++count);
  console.log(result.stdout); // 'hello'
})
.then(function(){
  return makeSpawnHello();
})
.then(function(result){
  console.log('output ' + ++count);
  console.log(result.stdout); // undefined <------ !!!!
})
.then(function(){
  return spawn('echo', ['hello'], { capture: ['stdout','stderr'] })
})
.then(function(result){
  console.log('output ' + ++count);
  console.log(result.stdout); // this one works (created new opts object)
})
.then(function(){
  console.info('all done')
});

output

output 1
hello

output 2
undefined
output 3
hello

all done

cause

https://github.com/Sequoia/child-process-promise/blob/master/lib/index.js#L93

How to use capture with async/await?

Hi, I'm trying to capture the stdout of a spawn process that uses await, here is an example:

const { childProcess } = await spawn('yarn', ['install'], { capture: ['stdout'] });
console.log(childProcess.stdout.toString()); // returns [object Object]

I'm would like to log the complete stdout of the process once this completes. Previously used {stdio: 'inherit'} but since there are concurrent process it's not possible to differentiate the different processes stdout.

Any help is much appreciated, many thanks!

stdin?

How would you feed a string to stdin of spawned child process?

How to do multiple commands?

I want a spawn process to do multiple commands in one line.

The terminal line looks like this: cd ~/folder && node test.js >> ./test.log

What's the correct way to do this?

My code is directly from the tutorial:

	let command = "cd ~/folder && node test.js >> ./test.log"
	logger.info("Spawning: " + command)
	var job = spawn(command);
	var childProcess = job.childProcess;

	logger.verbose('[spawn] childProcess.pid: ', childProcess.pid);
	childProcess.stdout.on('data', function (data) {
	    logger.verbose('[spawn] ' + childProcess.pid + ' stdout: ', data.toString());
	});
	childProcess.stderr.on('data', function (data) {
	    logger.verbose('[spawn] ' + childProcess.pid + ' stderr: ', data.toString());
	});
	 
	job.then(function () {
        logger.verbose('[spawn] ' + childProcess.pid + ' done!');
    })
    .catch(function (err) {
        logger.error('[spawn] ' + childProcess.pid + ' ERROR: ', err);
    });

Improve docs for idiots like me (multiple args format to spawn).

I honestly can't say this is an issue with the library.

But a minor change to the docs could have saved me an hour in lost-land. My story:

const promise = spawn( webpackBin, [ `--config ${ configFilePath }` ] )

In retrospect, I've just used the mapping:

exec('echo hello') > spawn('echo', ['hello'])

To do:

exec('webpack --config file' > spawn('webpack', ['--config file'].

It failed with code 1. I have been trying all sorts, looked at your own tests, enabled capture (only to realise after 15 minutes the output is above the screen top), and so on and so forth.

Now if you have experience with args, you'd know the process gets them as an array. So really the fix is:

const promise = spawn( webpackBin, [ `--config`, configFilePath ] )    

Would really help if in the docs instead of:

var promise = spawn('echo', ['hello']);

You use something like:

var promise = spawn('git', ['log', '--oneline']);

stream data to stdin of exec

when execing and exec ;) is it possible to send data to the stdin of the process you are starting

something more sophisticated than exec("echo 'foo' | someapp")

I have a json object that I want to stringify and pipe to the stdin of a process

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.