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
(MODULES-3636) Upgrade on non-English Windows #135
(MODULES-3636) Upgrade on non-English Windows #135
Conversation
@@ -14,8 +14,7 @@ if exist %pid_path% del %pid_path% | |||
|
|||
:wait_for_pid | |||
timeout /t 5 /nobreak > NUL | |||
FOR /F "tokens=*" %%A IN ('tasklist /FI "PID eq %AGENT_PID%" /NH') DO set _task=%%A | |||
echo %_task% | findstr "No tasks are running" >nul | |||
qprocess %AGENT_PID% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@ferventcoder asked about Nano... Nano doesn't have |
5b4a159
to
e15d9aa
Compare
@@ -14,8 +14,7 @@ if exist %pid_path% del %pid_path% | |||
|
|||
:wait_for_pid | |||
timeout /t 5 /nobreak > NUL | |||
FOR /F "tokens=*" %%A IN ('tasklist /FI "PID eq %AGENT_PID%" /NH') DO set _task=%%A | |||
echo %_task% | findstr "No tasks are running" >nul | |||
wmic path Win32_Process where handle=%AGENT_PID% get handle /format:textvaluelist | findstr /I "Handle=%AGENT_PID%" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tested that "Handle=PID"
appears on English and German... not sure about French or other languages.
Since it's a WMI property, I doubt that it's localized - but we might make the code a little more resilient if we just look for =PID
instead of Handle=PID
.
Thoughts @puppetlabs/windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you said findstr.exe also wasn't on nano?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find.exe
is not available, but findstr.exe
is fortunately
UPDATE: after changing the |
- The previous checks for PID running uses a combination of tasklist, findstr and some more cryptic batch-isms to detect if a puppet agent is currently executing (by PID). This check also relies on the English string "No tasks are running", because tasklist.exe doesn't set exitcodes as desired when the query is not a match. C:\Users\Administrator>tasklist.exe /FI "PID eq 1234" /NH INFO: No tasks are running which match the specified criteria. C:\Users\Administrator>echo %ERRORLEVEL% 0 There are a couple of alternative methods for achieving the desired functionality. The simplest is qprocess.exe: C:\Users\Administrator>qprocess 1234 No Process exists for 1234 C:\Users\Administrator>echo %ERRORLEVEL% 1 C:\Users\Administrator>qprocess 32936 USERNAME SESSIONNAME ID PID IMAGE >administrator console 1 32936 mmc.exe C:\Users\Administrator>echo %ERRORLEVEL% 0 Unfortunately qprocess is no longer available on Nano Server, so the next best option is wmic.exe, which exists everywhere. C:\>wmic PATH Win32_Process where handle=1111 get handle /format:textvaluelist | findstr /I "Handle=1111" No Instance(s) Available. C:\>echo %ERRORLEVEL% 1 The string 'Handle' appears everywhere, so no locale specific string parsing is required on non-English versions of Windows, such as German: C:\Users\moses>tasklist /FI "PID eq 1234" /NH INFORMATION: Es werden keine Aufgaben mit den angegebenen Kriterien ausgeführt. C:\Users\moses>echo %ERRORLEVEL% 0
e15d9aa
to
5da7b32
Compare
The previous checks for PID running uses a combination of tasklist,
findstr and some more cryptic batch-isms to detect if a puppet
agent is currently executing (by PID). This check also relies on
the English string "No tasks are running", because tasklist.exe
doesn't set exitcodes as desired when the query is not a match.
C:\Users\Administrator>tasklist.exe /FI "PID eq 1234" /NH
INFO: No tasks are running which match the specified criteria.
C:\Users\Administrator>echo %ERRORLEVEL%
0
There are a couple of alternative methods for achieving the
desired functionality. The simplest is qprocess.exe:
C:\Users\Administrator>qprocess 1234
No Process exists for 1234
C:\Users\Administrator>echo %ERRORLEVEL%
1
C:\Users\Administrator>qprocess 32936
USERNAME SESSIONNAME ID PID IMAGE
Unfortunately qprocess is no longer available on Nano Server, so
the next best option is wmic.exe, which exists everywhere.
C:>wmic PATH Win32_Process where handle=1111 get handle /format:textvaluelist |
findstr /I "Handle=1111"
No Instance(s) Available.
C:>echo %ERRORLEVEL%
1
The string 'Handle' appears everywhere, so no locale specific
string parsing is required on non-English versions of Windows, such
as German:
C:\Users\moses>tasklist /FI "PID eq 1234" /NH
INFORMATION: Es werden keine Aufgaben mit den angegebenen Kriterien ausgeführt.
C:\Users\moses>echo %ERRORLEVEL%
0