Skip to content

Error from cmd.exe printed if h5repack is not found. #693

@donno

Description

@donno

The Workspace.close() function attempts to call h5repack if repack is True.
When using group.add_children() the repack flag gets set to True.

On Windows because of the use of shell=True, this to run the argument via %ComSpec% which is typical cmd.exe or if missing cmd.exe. If cmd can't find the command/program it outputs the below error message on standard error.

Standard error is not being sent to DEVNUL as standard output is so the following message is printed:

'h5repack' is not recognized as an internal or external command,
operable program or batch file.

On Windows, if shell=True, then it tries to run the argument via %ComSpec% which is typical cmd.exe or if missing cmd.exe. If cmd can't find the command/program it outputs the above error message.

The simple fix would be like standard output, redirect standard error to DEVNUL.

Environment

  • Windows 10
  • Python 3.11
  • geoh5py 0.10.0
  • No h5repack executable on the search path ($env:PATH / %PATH%).

Minimal reproducible

from geoh5py.groups import ContainerGroup
from geoh5py.workspace import Workspace
if __name == "__main__":
    with Workspace.create(arguments.output) as workspace:
        group = ContainerGroup.create(workspace, name="Primary Group")
        sub_group = ContainerGroup.create(workspace, name="Sub Group")
        group.add_children(sub_group)

Suggested fix

Within geoh5py/workspace/workspace.py

                subprocess.run(
                    f'h5repack --native "{self._h5file}" "{temp_file}"',
                    check=True,
                    shell=True,
                    stdout=subprocess.DEVNULL,
                    stderr=subprocess.DEVNULL,  # Add this line.
                )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions