{"record":{"id":"b454ec45f1640a79","repo":"hankcs/HanLP","slug":"err-the-command-is-cmd","errorCode":null,"errorMessage":"{err}\nThe command is:\n{cmd}","messagePattern":"(.+?)\nThe command is:\n(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"hanlp/utils/io_util.py","lineNumber":604,"sourceCode":"    See https://stackoverflow.com/a/21000308/3730690\n\n    Args:\n      cmd: Command.\n\n    Returns:\n        Exit code, stdout, stderr.\n    \"\"\"\n    args = shlex.split(cmd)\n    proc = Popen(args, stdout=PIPE, stderr=PIPE)\n    out, err = proc.communicate()\n    exitcode = proc.returncode\n    return exitcode, out.decode('utf-8'), err.decode('utf-8')\n\n\ndef run_cmd(cmd: str) -> str:\n    exitcode, out, err = get_exitcode_stdout_stderr(cmd)\n    if exitcode:\n        raise RuntimeError(err + '\\nThe command is:\\n' + cmd)\n    return out\n\n\n@contextlib.contextmanager\ndef pushd(new_dir):\n    previous_dir = os.getcwd()\n    os.chdir(new_dir)\n    try:\n        yield\n    finally:\n        os.chdir(previous_dir)\n\n\ndef basename_no_ext(path):\n    basename = os.path.basename(path)\n    no_ext, ext = os.path.splitext(basename)\n    return no_ext\n","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/io_util.py#L586-L622","documentation":"run_cmd executes a shell command and, on a nonzero exit code, raises RuntimeError with the command's stderr followed by the exact command line. It is a thin wrapper around get_exitcode_stdout_stderr used by utilities like smatch_eval and official_conll_05_evaluate.","triggerScenarios":"Calling run_cmd('perl script.pl ...') etc. when the external tool (perl script, evaluation binary) fails: missing executable, bad arguments, unreadable files, or evaluation-script internal errors.","commonSituations":"Missing perl/malt/etc. on PATH; wrong paths passed to bundled eval scripts; AMR/CoNLL05 evaluation on malformed inputs.","solutions":["Read the stderr at the top of the message — it states the underlying failure (command not found, syntax error, missing file).","Fix prerequisites: install the tool, correct the paths, ensure input files exist.","Reproduce by pasting the command shown after 'The command is:' into a shell for interactive debugging."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import shutil\nfor tool in ['perl']:\n    assert shutil.which(tool), f'{tool} required for external eval'","typeGuard":null,"tryCatchPattern":"try:\n    out = run_cmd(cmd)\nexcept RuntimeError as e:\n    log.error('external eval failed: %s', e)\n    raise","preventionTips":["Smoke-test external eval scripts in CI with tiny inputs.","Wrap run_cmd and log both stderr and the command for reproducibility."],"tags":["subprocess","shell","evaluation","external-tool"],"backgroundTag":"subprocess-exit-nonzero","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}