New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shelljs auto generate some files? #619
Comments
This is an unfortunate aspect of how
|
Nothing we can do to fix this, so I'm closing this |
@nfischer I had the same question about the temp files, found this bug. Could you explain what you mean when you say that |
> shell.exec('echo hello world');
hello world
> child_process.execSync('echo hello world'); // silent |
But this works to get the same effect:
You can also control the three standard file descriptors individually. Does this allow a simpler implementation that won't need to generate temp files? |
Yup
We tried this in the past. I think you'll find that you see output like this: > var result = child_process.execSync('echo hello world', { stdio: 'inherit' }); // prints to console
hello world
> console.log(result); // result is null, not a Buffer
null
> console.log(result === null);
true The only way I know to print output to the console and to also return it from a sync function is the way we've implemented. Please correct me if I'm wrong--we've recently dropped support for anything below v4, so we might have more options available now. |
So the goal is to get it both on console/screen and capture it in a Node.js Buffer. Is that right? |
That's the current behavior of |
Thanks Nate. I've been in the dev game for over 40 years now, but I'm still rather new to Node.js. I'm sort of feeling my way through issues like how to best |
@nfischer I left a comment on another issue (#724 (comment)) regarding this very problem. In short, we don't need to create temp files and fork node in I think this method would be much more reliable and secure than writing temp files with executable code. |
Can you provide a minimal proof of concept?
This was one of the design considerations of #524 |
How very interesting @freitagbr. I'd love to see that proof of concept too. You said:
I'm not familiar with these tests, can you summarize briefly how that's done in those tests? |
The reason the temp-file-and-fork method was used was because we needed to print the stdout/stderr of the spawned process in real-time, but also return all of the data printed to stdout from the This method does the same, but without forking node or using temp files. The simplified procedure goes something like this: // set up the intercepts for process.stdout.write, process.stderr.write
var stdio = intercept.init();
// use stdio: 'inherit' here, so the stdio from the spawned command is piped to
// the stdio of the node process itself
child_process.execSync(cmd, { stdio: 'inherit' });
// retrieve the string values of the data output to stdout and stderr
var stdout = stdio.stdout();
var stderr = stdio.stderr();
// restore the original process.stdout.write and process.stderr.write
stdio.restore(); Here is a module that does this stdout/stderr intercepting that I demonstrate above: sfarthin/intercept-stdout. We may want to base our implementation on this. And here is the way stdout/stderr are mocked in the echo tests (note that with these mocks, nothing is printed to stdout or stderr): Another consideration is that |
I don't think this works. Try this example that's been adapted from their README: var intercept = require('intercept-stdout');
var child_process = require('child_process');
var captured_text = '';
var unhook_intercept = intercept(function(text) {
captured_text += text;
});
child_process.execSync('echo this text is being captured', { stdio: 'inherit' });
// Stop capturing stdout.
unhook_intercept();
console.log('This text is not being captured.');
// This is the text that was captured.
console.log('CAPTURED:', captured_text); // @freitagbr you'll find this to be empty
I agree with the suggestion, but Don't pass arbitrary user input to any of our functions. #345 has an example.
This is the main motivation for #524. Discussed to length in #143, #495, #103. Please don't open another issue. |
Node version (or tell us if you're using electron or some other framework):6.9.1
ShellJS version (the most recent version/Github branch you see the bug on):0.7.0
Operating system:centos x86_64
Description of the bug:auto generate three file like shelljs_*
Example ShellJS command to reproduce the error: no
shelljs auto generate 3 fiels:
How to disable this? Thanks
The text was updated successfully, but these errors were encountered: