Skip to content
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

stdout includes prompt + command on Windows #116

Closed
mathiasbynens opened this issue Dec 6, 2017 · 10 comments · May be fixed by nju33/remonade#121
Closed

stdout includes prompt + command on Windows #116

mathiasbynens opened this issue Dec 6, 2017 · 10 comments · May be fixed by nju33/remonade#121
Labels

Comments

@mathiasbynens
Copy link

mathiasbynens commented Dec 6, 2017

On this line: https://github.com/GoogleChromeLabs/jsvu/blob/905885652848add5f8fe27bb909057fe777974ab/engines/chakra/test.js#L29

stdout is equal to:

"\r\nC:\\Users\\jsvu>\"C:\\Users\\jsvu/.jsvu/engines/chakra\\chakra.exe\" \"C:\\Users\\jsvu\\AppData\\Local\\Temp\\3a4c2232c333e7ab7da85331c1dfe4e4\" \r\nHi!"

The expected value is only the actual stdout, which is:

"Hi!"

In case it matters, this happens after running a batch script chakra.cmd with the following contents:

"C:\Users\jsvu\.jsvu\engines\chakra\chakra.exe" %*
@SamVerschueren
Copy link
Contributor

I'll try to have a look when I find some time :).

@mathiasbynens
Copy link
Author

FWIW, adding @echo off to the batch script prevents the visual expansion from happening and works around this execa bug.

@SamVerschueren
Copy link
Contributor

Hi @mathiasbynens. I looked into this and I can reproduce the issue with a simple ECHO Hello World in a hello.cmd file. However, this does not appear to be a execa bug.

const cp = require('child_process');

childProcess.exec('hello.cmd', (err, stdout) => {
    console.log(stdout);
    //=> '\r\nC:\\Users\\Sam\\Projects\\test>ECHO Hello World\r\nHello World\r\n'
});

I looked into the options of child_process and tried to Google for some answers to the question "Why this behaviour?". Couldn't find any...

So not sure how to continue from here. Do you happen to know someone who might know more? Should we open an issue in the Node.js repository?

@mathiasbynens
Copy link
Author

I agree this is not strictly an execa bug, but rather a quirk of how Windows/cmd.exe works. If providing a cross-platform stdout that makes sense is a goal of this project, it would be nice if execa worked around it.

@mathiasbynens
Copy link
Author

I should note that it’s unclear (to me) if it’s even possible to work around this behavior in a reliable/robust way.

@SamVerschueren
Copy link
Contributor

SamVerschueren commented Dec 19, 2017

Alright, I was too fast. I found the reason for this behaviour and also found a solution.

To run the hello.cmd file I wrote from the command line, you would have to use cmd.exe /c hello.cmd. This results in the exact same output as we are experiencing. However, cmd.exe has a /q flag which turns off the echo thingy, which you did manually with @echo off.

So in the background we use node-cross-spawn to make things easier. It already adds a couple of flags right here, but not the /q flag. I just checked manually in the execa code if cmd.exe was used as a command and pushed the /q flag onto the arguments and it worked.

Are there any downsides of always turning off echo? Is it ok to do it or can we break some behaviour?

@mathiasbynens
Copy link
Author

I guess that would break cases where people rely on the current behavior — but it’s unclear if there are any. The behavior is weird, and relying on it seems even weirder, IMHO. What does @sindresorhus think?

@SamVerschueren
Copy link
Contributor

I'm not really into batch files, but what does @echo off do exactly? I looked it up but couldn't find a decent answer. Does it only hide the executing command in this case? Or will/can it hide other information as well further down in the cmd file?

I totally agree that it's weird and IMO we should turn it off, if it doesn't have other implications.

@sindresorhus
Copy link
Owner

sindresorhus commented Dec 25, 2017

Yes, I think we should include the /q flag. I can't imagine anyone depending on this and if they do, they can just use a different module or child_process directly.

@SamVerschueren
Copy link
Contributor

@mathiasbynens version 0.9.0 is released with this fix. Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants