#1782 closed defect (fixed)

Windows drivedb update script returns "gpg.exe gpg.exe is not recognized..."

Reported by: Adam Piggott Owned by: Christian Franke
Priority: major Milestone: Release 7.5
Component: all Version: 7.4
Keywords: windows Cc:

Description (last modified by Christian Franke)

When I try to execute the update-smart-drivedb.ps1 script in a Powershell or Command Prompt CLI (running as Administrator or not) I receive the error:

& : The term 'gpg.exe gpg.exe' 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 update-smart-drivedb.ps1:500 char:16
+   $($input | & $cmdobj @args 2>&1) | %{ $_.ToString() }
+                ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (gpg.exe gpg.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

update-smart-drivedb.ps1 version 5515 2023-07-24 12:58:25Z from smartmontools 7.4, on Windows 10 22H2 64-bit, Powershell 10.0.19041.3636. gpg.exe is in $PATH and works.

Change History (6)

comment:1 by Christian Franke, 12 months ago

Description: modified (diff)

comment:2 by Christian Franke, 11 months ago

Keywords: windows added
Milestone: undecided

Could not reproduce the problem. With same script version on Win10 22H2 and gpg.exe in PATH it works as expected.

Powershell version:

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.3570
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3570
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Does it work with -NoVerify?

comment:3 by Adam Piggott, 11 months ago

-NoVerify works. I get the same failure when gpg.exe is in the same directory as the updater script.

Is the fact that the script appears to try to launch "gpg.exe gpg.exe" relevant? Looking through a Sysinternals Process Monitor trace, powershell.exe searches the directories in PATH for "gpg.*" and get a success result in gpg.exe's parent directory, for "gpg.exe". Afterwards it then issues searches for "gpg.exe gpg.exe.*" in the same directories and gets no results.

From the same Powershell prompt:

> gpg --version
gpg (GnuPG) 2.4.3
libgcrypt 1.10.2

Powershell version table shows mine is somewhat more recent. I haven't manually installed or changed my Powershell install (other than to allow execution of 'untrusted' scripts).

PSVersion                      5.1.19041.3758
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3758
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Last edited 11 months ago by Adam Piggott (previous) (diff)

comment:4 by Adam Piggott, 11 months ago

It looks like the bug triggers when there are more than one matches of gpg.exe in PATH; I have two. When I renamed one, the update script works.

A friend suggested that $cmdobj = Get-Command -CommandType Application -Name $cmd returns all of the results, which is why you and I are seeing different results. It looks like there are several places in the script where similar code is used, which could all be affected if more than one .exe are found.

comment:5 by Christian Franke, 11 months ago

Milestone: undecidedRelease 7.5
Owner: set to Christian Franke
Priority: minormajor
Status: newaccepted

Indeed, GetCommand returns an array of all results. Thanks to your friend for pointing this out!

This change should do the trick:

-  $($input | & $cmdobj @args 2>&1) | %{ $_.ToString() }
+  $($input | & $cmdobj[0] @args 2>&1) | %{ $_.ToString() }

The other usages require a closer look.

comment:6 by Christian Franke, 11 months ago

Resolution: fixed
Status: acceptedclosed
Note: See TracTickets for help on using tickets.