{"record":{"id":"1e7fe9851a2ed67c","repo":"Yalantis/uCrop","slug":"load-medcon-external-failed-to-load-file-s-w","errorCode":null,"errorMessage":"load_medcon_external(): Failed to load file '%s' with external command 'medcon'.","messagePattern":"load_medcon_external\\(\\): Failed to load file '(.+?)' with external command 'medcon'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59881,"sourceCode":"        throw CImgArgumentException(_cimg_instance\n                                    \"load_medcon_external(): Specified filename is (null) or does not exist.\",\n                                    cimg_instance);\n      CImg<charT> command(1024), filename_tmp(256), body(256);\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s.hdr\",cimg::filenamerand());\n      } while (cimg::path_exists(filename_tmp));\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -w -c anlz -o \\\"%s\\\" -f \\\"%s\\\"\",\n                    cimg::medcon_path(),\n                    CImg<charT>::string(filename_tmp)._system_strescape().data(),\n                    CImg<charT>::string(filename)._system_strescape().data());\n      cimg::system(command,cimg::medcon_path());\n      cimg::split_filename(filename_tmp,body);\n\n      cimg_snprintf(command,command._width,\"%s.hdr\",body._data);\n      if (!cimg::path_exists(command)) {\n        cimg_snprintf(command,command._width,\"m000-%s.hdr\",body._data);\n        if (!cimg::path_exists(command)) {\n          throw CImgIOException(_cimg_instance\n                                \"load_medcon_external(): Failed to load file '%s' with external command 'medcon'.\",\n                                cimg_instance,\n                                filename);\n        }\n      }\n      load_analyze(command);\n      std::remove(command);\n      cimg::split_filename(command,body);\n      cimg_snprintf(command,command._width,\"%s.img\",body._data);\n      std::remove(command);\n      return *this;\n    }\n\n    //! Load image from a DICOM file, using Medcon's external tool 'medcon' \\newinstance.\n    static CImg<T> get_load_medcon_external(const char *const filename) {\n      return CImg<T>().load_medcon_external(filename);\n    }\n","sourceCodeStart":59863,"sourceCodeEnd":59899,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59863-L59899","documentation":"load_medcon_external() runs the external 'medcon' tool to convert a DICOM file to an Analyze (.hdr/.img) pair in a temp location, then looks for the generated header file (<body>.hdr or m000-<body>.hdr). If neither exists after medcon ran, it throws this CImgIOException: the external conversion produced no usable output.","triggerScenarios":"Calling load_medcon_external(filename) where the 'medcon' command ran (or failed silently) but did not create the expected .hdr file — medcon not installed so the command did nothing, unsupported DICOM transfer syntax, or medcon naming its output differently than expected.","commonSituations":"medcon (xmedcon) not installed in the runtime environment; non-standard or corrupted DICOM files that medcon cannot convert; medcon version behaving differently about output filenames; read-protected input DICOM.","solutions":["Verify 'medcon' is installed and on PATH ('medcon -V'); install xmedcon if missing.","Run 'medcon -f <file> -c int -o /tmp' manually to see medcon's actual error on this DICOM.","Check the DICOM file is valid and readable ('dcmdump <file>' or similar) and not truncated.","Ensure the temp directory is writable so medcon can produce its .hdr/.img output.","Use a DICOM library (e.g. dcmtk) or pre-converted Analyze/NIfTI file instead of the external path."],"exampleFix":"// before\nimg.load_medcon_external(\"scan.dcm\");\n// after\nif (cimg::system(\"medcon -V\",\"medcon\")!=0)\n  throw std::runtime_error(\"medcon not installed\");\nimg.load_medcon_external(\"scan.dcm\");","handlingStrategy":"try-catch","validationCode":"if (!path || !cimg::is_file(path)) throw std::invalid_argument(\"DICOM missing\");\nif (cimg::system(\"medcon -V\",\"medcon\")!=0) throw std::runtime_error(\"medcon not installed\");","typeGuard":"bool medconReady(const char* p){ return p && cimg::is_file(p) && cimg::system(\"medcon -V\",\"medcon\")==0; }","tryCatchPattern":"try { img.load_medcon_external(path); }\ncatch (CImgIOException& e) { log(\"medcon conversion produced no output; check DICOM validity\"); throw; }","preventionTips":["Install xmedcon/medcon in deployment images","Validate DICOMs with dcmdump before conversion","Keep temp dirs writable","Consider dcmtk/LibRaw-style libraries instead of shelling out"],"tags":["dicom","medcon","external-tool","temp-file","cimg"],"backgroundTag":"command-not-found","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}