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
(some) command read from stdin seem to require extra trailing newline #21644
Comments
btw: The background to this is that I wanted to be able to start scripts from a shell script like in:
|
Oh and I should mention why I titled "(some) commands": E.g. just
seems to work fine, even without the extr newline before the |
Just noted, that it doesn't need to be an extra newline to make it work. Seems any even non-newline-terminated character after the newline from the last actual command line makes it work. For example, the following doesn't work:
while when there's an extra space (or e.g.
Interestingly, it seems if the extra char is missing, then powershell doesn't even execute the command. Originally I had a quoting error in my code (the
No error messages are printed, while in:
there are. |
As noted in #3223, it is multiline statements that need an extra trailing newline in order to be recognized as a complete statement by the REPL-like behavior exhibited by So, thank your opening this a separate issue, which can be dealt with in the context of the by-design REPL behavior. The extra trailing newline required to terminate a multiline statement appears to be by design (the same behavior applies in an interactive session with The real bug here is that an incomplete statement is ignored; quoting @SeeminglyScience from #15331 (comment):
|
Prerequisites
Steps to reproduce
I see the following in current PowerShell versions back to the days of
powershell.exe
.Having the following files:
(i.e. happens with both, LF and CRLF newlines)
and executing them via
-File
works as expected:But If I do the same from stdin:
there's no output at all and the exit code is still
0
.It does suddenly work, if I add another trailing newline (either LF or CRLF) at the end of the file.
What also works is:
This is executed from
bash
, and the string passed as argv to-Command
contains a LF newline, i.e. binary it looks like:So if the command is given as string, it works even without terminating newline for the last line.
Any ideas why it doesn't work when reading the command from stdin?
btw: I do the this on Windows and invoking Cygwin.
Thanks,
Philippe
Expected behavior
Should execute the command.
Actual behavior
Doesn't execute the command, or at least produces no output.
Error details
No response
Environment data
gives no output either ;-)
The text was updated successfully, but these errors were encountered: