{"id":21593,"library":"mozshellutil","title":"mozshellutil","description":"MozShellUtil is a Python library providing shell command line parsing utilities for Mozilla testing. It offers functionality to parse and execute shell commands in a cross-platform manner, handling quotes, variables, and subprocess launching. The current version is 1.0.0, with a requirement of Python >=3.8. The library is maintained by the Mozilla community and released as needed.","status":"active","version":"1.0.0","language":"python","source_language":"en","source_url":"https://github.com/mozilla/mozshellutil","tags":["mozilla","testing","shell","command-line","utilities"],"install":[{"cmd":"pip install mozshellutil","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Used for file manipulation and temp directories.","package":"mozfile","optional":true}],"imports":[{"note":"Module name is lowercase 'mozshellutil'.","wrong":"from MozShellUtil import Shell","symbol":"Shell","correct":"from mozshellutil import Shell"},{"note":"Command is exported directly from the package.","wrong":"from mozshellutil.command import Command","symbol":"Command","correct":"from mozshellutil import Command"}],"quickstart":{"code":"from mozshellutil import Shell, Command\n\nshell = Shell()\n# Run a simple command\nresult = shell.run(Command(['echo', 'hello']))\nprint(result.stdout)  # b'hello\\n'\n\n# With arguments and environment\nenv = {'MY_VAR': 'value'} if os.environ.get('TEST') else {}\nresult = shell.run(Command(['printenv', 'MY_VAR'], env=env))\nprint(result.returncode)","lang":"python","description":"Creates a Shell instance to run Command objects. Each Command specifies the executable and arguments, and optionally an environment. The run method returns a CompletedProcess-like object."},"warnings":[{"fix":"Use shell-specific expansion (e.g., os.path.expandvars) before creating Command.","message":"Command line parsing is minimal. Shell.run does not expand environment variables in arguments by default; you must pass them explicitly in the env dict.","severity":"breaking","affected_versions":"all"},{"fix":"Access result.stdout.decode('utf-8') for string output.","message":"Shell.run returns a MozShellResult object, not subprocess.CompletedProcess. Its fields are stdout, stderr, returncode but as bytes. Decode manually if needed.","severity":"gotcha","affected_versions":"all"},{"fix":"Always provide a list of strings, e.g., Command(['ls', '-la']).","message":"Do not pass a list of strings as a single string to Command; it expects a sequence. Passing a string will treat each character as a separate argument.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use 'from mozshellutil import Shell'.","cause":"Incorrect import path; likely imported the package but the symbol is not directly under the module.","error":"AttributeError: module 'mozshellutil' has no attribute 'Shell'"},{"fix":"Change Command('ls -la') to Command(['ls', '-la']).","cause":"Passed a string instead of a list to Command.","error":"TypeError: Command() argument after * must be an iterable, not str"},{"fix":"Ensure the command ran successfully. Use result.returncode to check first. If using an older version, upgrade to 1.0.0.","cause":"Trying to access stdout on a result that failed or library version mismatch.","error":"MozShellResult object has no attribute 'stdout'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}