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

Open cmd when running inside PowerShell #494

Merged
merged 1 commit into from
May 20, 2020
Merged

Open cmd when running inside PowerShell #494

merged 1 commit into from
May 20, 2020

Conversation

arpontes
Copy link
Contributor

As of today, when VSCode default's terminal is PowerShell, running a maven command opens a new cmd window, and when the process is finished, this window is closed and we can't see what happened.

With this change, we force PowerShell to run the command in it's own window.

As of today, when VSCode default's terminal is PowerShell, running a maven command opens a new cmd window, and when the process is finished, this window is closed and we can't see what happened.

With this change, we force PowerShell to run the command in it's own window.
@Eskibear
Copy link
Member

Also reported in #489 , but I was not able to reproduce the bug.
In my observation, with "cmd /c", powershell just executed the command in the integrated terminal, without poping up new a window. Can you share the version of your powershell?

BTW, the "cmd /c" trick was to cover some corner case (if I don't remember wrong). I'll let you know when I find out the back-story.

@arpontes
Copy link
Contributor Author

I think I found something that could help to understand the issue.

In my settings.json, the configurations relative to java and maven are:
"java.home": "D:\java\jdk-14.0.1",
"maven.executable.path": "D:\java\plugins\maven\lib\maven3\bin\mvn",
"maven.terminal.useJavaHome": true

This way, a new cmd window pops out and closes as soon as the execution ends, therefore I can't see what happened.

I found out that when I reference the .cmd version of mvn, the results are printed to PS terminal window, without opening a new one.
"maven.executable.path": "D:\java\plugins\maven\lib\maven3\bin\mvn.cmd"

So, that's why the "cmd /c" works! When running "cmd /c", even if we don't put .cmd, it reached for mvn.cmd.

@Eskibear
Copy link
Member

I find the story. Before PR #455 , we do have "cmd /c" . You may take a look at it if you have interest. Anyway, now since it's breaking your case, I agree that we add it back.

Copy link
Member

@Eskibear Eskibear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! We'll add your case into the test plan in case of any regression.

@Eskibear Eskibear merged commit 05280e7 into microsoft:master May 20, 2020
@arpontes arpontes deleted the patch-1 branch May 20, 2020 20:02
@Eskibear
Copy link
Member

Eskibear commented May 26, 2020

@arpontes
The "cmd /c" solution doesn't work for some corner cases. Running a regression test, we find that if you have whitespaces in the path, the command will not be correctly parsed by powershell (#498 ). I think that's the reason why we swtiched to "&" solution long time ago.

Screen Shot 2020-05-26 at 3 50 56 PM

To fix the issue you mentioned, what I'm thinking now is:

  • revert this PR to use "&" solution.
  • on windows, once we detect maven.executable.path is set to "path/to/mvn", we append ".cmd" before executing it.

@arpontes
Copy link
Contributor Author

@Eskibear actually, the problem is the enclosing quotes.
This seems like a cmd bug to me, but the problem is: when we call cmd /c, the entire sequence should be evaluated by cmd, and the parameters should be passed to the executable (or batch) in the first parameter.

I created a series of folders with an .cmd file that contains only a "dir".
d:\dev\teste.cmd
d:\dev\plugins test\teste.cmd
(and much more)
All of then runned fine.

Then I start to test some parameters, and the problem arose:
cmd /c "D:\test\plugins test\teste.cmd" "x y"
See, the problem cames when the batch file is in a folder with space AND there's another parameter with a space.

The problem is solved if we enclose all the command in quotes (scaping the original quotes):
cmd /c """D:\test\plugins test\teste.cmd"" ""d:\deva test"""

The same worked with maven:
cmd /c """D:\java\plugins test\maven\lib\maven3\bin\mvn.cmd"" clean -f ""D:\dev test\almundo\api-self-management-reservations\pom.xml"""

Actually, this was the right way to call cmd in order to be a single command - including the parameters
... :-)
But if you already have done the change you suggested, I think it's fine too.

@Eskibear
Copy link
Member

Thanks for the information, and it helps me understand more about the behavior.
For the moment, if the issue can be addressed by forcing to use mvn.cmd on Windows, I think it's more wise to make minimal changes, instead of using double/triple quotes.
We'll revisit your proposal and refer to official docs/guides of powershell if new problem comes.

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

Successfully merging this pull request may close these issues.

None yet

2 participants