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

#198: fixed powershell integration #208

Merged
merged 2 commits into from
Aug 21, 2019
Merged

#198: fixed powershell integration #208

merged 2 commits into from
Aug 21, 2019

Conversation

hohwille
Copy link
Member

fix for #198

@hohwille hohwille added bug Something isn't working enhancement New feature or request windows specific for Microsoft Windows OS powershell specific for Microsoft PowerShell labels Aug 21, 2019
@hohwille hohwille added this to the release:3.0.0 milestone Aug 21, 2019
@hohwille
Copy link
Member Author

I found another bug and I assume this could never ever have worked before:
When powershell runs a command (e.g. devon.bat) it does not behave like CMD but like a real shell. That is, it creates a sub-shell where all the side-effects of that command take place but they do not interfere the parent shall. Therefore devon.bat can properly set the path but afterwards it exists and returns to the powershell that does not see any of these changes to environment variables.
That is why we are not executing the devon command in bash but source it. As CMD is based on the side effects we had this different approach for windows CMD so far.
AFAIK there is no source for powershell to run a bat file allowing modifications of env variables. This would mean:

  • We had to run devon.bat prior to running powershell so it is inheriting the changes.
  • We can not update the environment variables in powershell with just running devon command what makes powershell support still kind of broken.
  • Alternatively we could make devon command open a new powershell session after setting environment variables. This could however, lead to ugly cascaded nesting of shells.

@hohwille
Copy link
Member Author

I was wrong about powershell. Sourcing is supported:
https://superuser.com/questions/71446/equivalent-of-bashs-source-command-in-powershell

@hohwille
Copy link
Member Author

Sorry to say so, but powershell is broken. Maybe it is because windows 10 comes with powershell 1.0 while version 6 is already out. But this entirely sucks and I am giving up. It seems that some windows fan who is keen on powershell support would need to take over.

PS C:\projects\cool-project\system\windows\power-shell> . $env:USERPROFILE/scripts/devon.bat
devon-ide environment variables have been set for C:\projects\cool-project in workspace main
PS C:\projects\cool-project\system\windows\power-shell> mvn -v
mvn : The term 'mvn' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ mvn -v
+ ~~~
    + CategoryInfo          : ObjectNotFound: (mvn:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\projects\cool-project\system\windows\power-shell> echo $env:PATH
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Users\hohwille\AppData\Local\Microsoft\WindowsApps;C:\Users\hohwille\scripts;
PS C:\projects\cool-project\system\windows\power-shell> devon mvn -v
Running: /c/projects/cool-project/software/maven/bin/mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T21:00:29+02:00)
Maven home: C:\projects\cool-project\software\maven
Java version: 11.0.4, vendor: AdoptOpenJDK, runtime: C:\projects\cool-project\software\java
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
devon-ide environment variables have been set for C:\projects\cool-project in workspace main
PS C:\projects\cool-project\system\windows\power-shell>

@hohwille
Copy link
Member Author

Set-Alias : A positional parameter cannot be found that accepts argument 'C:\Users\hohwille\scripts\devon.bat'.
At \\vmware-host\Shared Folders\Documents\WindowsPowerShell\profile.ps1:1 char:1
+ Set-Alias -Name devon -Value . $env:USERPROFILE\scripts\devon.bat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Alias], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand

So all tricky and nothing working as expected with powershell.
Even

echo Welcome to PowerShell

Is giving this output:

Welcome
to
PowerShell

There are really nice concepts in PowerShell but I am facing too many drawbacks here.

I think it is a good move that Microsoft deeply integrates bash, ssh and the entire linux subsystem as well as docker into windows. I will therefore focus on bash and leave powershell support open to some drivers who really want to have this feature. I will do a minimum fix now and are done.

BTW: profile.ps1 is not resolved from $env:USERPROFILE\Documents\WindowsPowerShell\profile.ps1. On my machine Documents are mounted from VMWareFusion to a totally different location:

$profile | Format-List * -force

AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    : \\vmware-host\Shared Folders\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : \\vmware-host\Shared Folders\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length                 : 89

So if someone wants to take over, he would have to figure out via which variables one can figure out where to put or find profile.ps1.

@hohwille hohwille merged commit 759bf41 into devonfw:master Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request powershell specific for Microsoft PowerShell windows specific for Microsoft Windows OS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant