apache / maven-mvnd

Apache Maven Daemon
https://maven.apache.org/
Apache License 2.0
2.91k stars 207 forks source link

wmic is required on windows #659

Open j3rem1e opened 2 years ago

j3rem1e commented 2 years ago

My environment has a GPO on wmic: I can't execute it with a user account.

mvnd doesn't show any output in this environment.

C:\DEV>mvnd --status
      ID      PID                   Address   Status    RSS            Last activity  Java home

[main] WARN org.mvndaemon.mvnd.common.OsUtils - Could not execute wmic process where processid=17288 get WorkingSetSize
[main] WARN org.mvndaemon.mvnd.common.OsUtils - Unexpected output of wmic process where processid=17288 get WorkingSetSize:
89301fbf    17288     inet:/127.0.0.1:61590     Idle    -1k  2022-06-23T13:48:31.527  C:\Program Files\RedHat\java-11-openjdk-11.0.14-1
ppalaga commented 2 years ago

Hi @j3rem1e, thanks for the report. Could you please explain what is GPO? What would you expect from mvnd in this situation? Maybe an explicit error message?

j3rem1e commented 2 years ago

Sorry for the delay..

A GPO is a "Group Policy" on windows: an administrator can define rules on a windows domain. In my corporate environment, wmic is forbidden because of a GPO.

However, after reading the source, I think I was wrong and that wmic is not really required, the error seem to be correctly handled by mvnd. I have to search why mvnd doesn't work anymore on my computer (it was working with v0.7 but not v0.8)

mvnd seem to be locked, waiting for something, and mvnd --status :

      ID      PID                   Address   Status    RSS            Last activity  Java home

[main] WARN org.mvndaemon.mvnd.common.OsUtils - Could not execute wmic process where processid=11240 get WorkingSetSize
[main] WARN org.mvndaemon.mvnd.common.OsUtils - Unexpected output of wmic process where processid=11240 get WorkingSetSize:
8a8b25bc    11240     inet:/127.0.0.1:64317  Canceled    -1k  2022-09-08T17:23:38.964  C:\Program Files\RedHat\java-11-openjdk-11.0.14-1
j3rem1e commented 2 years ago

when using mvnd -e -Dmvnd.noBuffering=true clean install I can see the build running normally. without this option, I don't have any progress in the console.

pshiner commented 1 week ago

I ran into the same issue, likely because of a group policy.

While looking for solutions I noticed this:

Important

WMIC is deprecated as of Windows 10, version 21H1; and as of the 21H1 semi-annual channel release of Windows Server. This utility is superseded by Windows PowerShell for WMI; see Chapter 7 - Working with WMI. This deprecation applies only to the WMIC utility. Windows Management Instrumentation (WMI) itself is not affected. Also see Windows 10 features we're no longer developing.

WMIC: WMI command-line utility, Article, 07/15/2024

The Maven Daemon works though as expected. Just those warning messages.

Looks like the call is here? https://github.com/apache/maven-mvnd/blob/9f4b57be26a5a979fc9aebfc20e3c23e087f7648/common/src/main/java/org/mvndaemon/mvnd/common/OsUtils.java#L83

I am using both PowerShell and a normal Command Prompt (cmd.exe) with the same results.

Maybe a recommendation to turn off that particular warning message??

gnodet commented 1 week ago

I ran into the same issue, likely because of a group policy.

While looking for solutions I noticed this:

Important WMIC is deprecated as of Windows 10, version 21H1; and as of the 21H1 semi-annual channel release of Windows Server. This utility is superseded by Windows PowerShell for WMI; see Chapter 7 - Working with WMI. This deprecation applies only to the WMIC utility. Windows Management Instrumentation (WMI) itself is not affected. Also see Windows 10 features we're no longer developing.

WMIC: WMI command-line utility, Article, 07/15/2024

The Maven Daemon works though as expected. Just those warning messages.

Looks like the call is here?

https://github.com/apache/maven-mvnd/blob/9f4b57be26a5a979fc9aebfc20e3c23e087f7648/common/src/main/java/org/mvndaemon/mvnd/common/OsUtils.java#L83

I am using both PowerShell and a normal Command Prompt (cmd.exe) with the same results.

Maybe a recommendation to turn off that particular warning message??

What about fixing the call ? I think it should roughly look like:

String[] cmd = {"powershell", "-Command", "Get-Process -Id " + pid + " | Select-Object -ExpandProperty WorkingSet" }
pshiner commented 1 week ago

@gnodet , thanks for the quick note. What I have found for my environment:

TL;DR - I use both cmd.exe and powershell.exe command windows depending on the situation. Commands that work in one break the other (? - at least so far for me as I learn. ) Looks like two (2) issues then, which shell, what new command string.

Finding PowerShell ( if in cmd.exe window )

  1. PowerShell is not in my default PATH. Not sure if my Windows host is a normal setup.
  2. My PowerShell shortcuts use the following to launch: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
  3. I've seen a reference to a PSHOME environment variable, but that is not present on my system.
  4. I've seen a StackOverflow thread indicating it is always located in the v1.0 folder.

Works from a Command Window ( cmd.exe )

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "get-process -id 6448 | select-object -expandproperty workingset"

Works from a PowerShell Window ( powershell.exe )

get-process -id 6448 | select-object -expandproperty workingset

This article seems to provide a useful process for determining which shell is the process parent.

How do I determine if I'm in powershell or cmd?

C:\>(dir 2>&1 *`|echo CMD);&<# rem #>echo ($PSVersionTable).PSEdition
CMD
PS C:\> (dir 2>&1 *`|echo CMD);&<# rem #>echo ($PSVersionTable).PSEdition
Desktop

Hope this helps.