{"record":{"id":"08eb7dac13e9c811","repo":"Yalantis/uCrop","slug":"save-medcon-external-failed-to-save-file-s-w","errorCode":null,"errorMessage":"save_medcon_external(): Failed to save file '%s' with external command 'medcon'.","messagePattern":"save_medcon_external\\(\\): Failed to save file '(.+?)' with external command 'medcon'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63843,"sourceCode":"    **/\n    const CImg<T>& save_medcon_external(const char *const filename) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_medcon_external(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n\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      save_analyze(filename_tmp);\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -w -c dicom -o \\\"%s\\\" -f \\\"%s\\\"\",\n                    cimg::medcon_path(),\n                    CImg<charT>::string(filename)._system_strescape().data(),\n                    CImg<charT>::string(filename_tmp)._system_strescape().data());\n      if (cimg::system(command,cimg::medcon_path())!=0)\n        throw CImgIOException(_cimg_instance\n                                \"save_medcon_external(): Failed to save file '%s' with external command 'medcon'.\",\n                                cimg_instance,\n                                filename);\n      std::remove(filename_tmp);\n      cimg::split_filename(filename_tmp,body);\n      cimg_snprintf(filename_tmp,filename_tmp._width,\"%s.img\",body._data);\n      std::remove(filename_tmp);\n\n      if (!cimg::path_exists(filename)) {\n        cimg_snprintf(command,command._width,\"m000-%s\",filename);\n        if (!cimg::path_exists(command)) {\n          cimg::fclose(cimg::fopen(filename,\"r\"));\n          throw CImgIOException(_cimg_instance\n                                \"save_medcon_external(): Failed to save file '%s' with external command 'medcon'.\",\n                                cimg_instance,\n                                filename);\n        }\n      }","sourceCodeStart":63825,"sourceCodeEnd":63861,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63825-L63861","documentation":"save_medcon_external() first saves the image in ANALYZE format to a temp file, then runs the external 'medcon' tool to convert it to DICOM. This error is thrown when the 'medcon' system command returns a non-zero exit status, meaning the DICOM conversion failed and the target file was not produced.","triggerScenarios":"Calling save_medcon_external(filename) when: medcon is not installed or cimg::medcon_path() is wrong; the medcon DICOM conversion fails on the generated ANALYZE temp data (unsupported dimensions/pixel type); permissions or disk issues abort the conversion.","commonSituations":"Medical imaging pipelines deployed on hosts without (X)Medcon installed; medcon version too old for the image geometry; 3D/volumetric or unusual pixel-type images that medcon's dicom converter rejects.","solutions":["Verify medcon is installed and cimg::medcon_path() points to it; run the constructed 'medcon -w -c dicom ...' command manually to see the real error.","Install or upgrade (X)Medcon to a version supporting the image geometry/pixel type.","Check that the temp and output directories are writable.","Convert the image to a supported type/geometry before calling save_medcon_external().","Use an alternative DICOM writing library (e.g. dcmtk) if medcon is unavailable."],"exampleFix":"// before\nimg.save_medcon_external(\"slice.dcm\");\n// after\ntry { img.save_medcon_external(\"slice.dcm\"); }\ncatch (CImgIOException& e) { std::fprintf(stderr, \"medcon failed: %s\", e.what()); img.save_analyze(\"slice.img\"); }","handlingStrategy":"try-catch","validationCode":"bool medconAvailable() { return std::system(\"medcon -v > /dev/null 2>&1\") == 0; }\n// also ensure image geometry/type are DICOM-compatible before saving","typeGuard":null,"tryCatchPattern":"try {\n  img.save_medcon_external(dicomFile);\n} catch (CImgIOException& e) {\n  std::fprintf(stderr, \"medcon conversion failed: %s\", e.what());\n  // fall back to ANALYZE output or another DICOM writer\n}","preventionTips":["Install (X)Medcon on all hosts running the pipeline and check medcon_path().","Match image dimensions/pixel type to what medcon's DICOM encoder accepts.","Keep temp and output directories writable.","Test with the medcon version deployed; output behavior varies between versions."],"tags":["io","external-command","medcon","dicom","medical-imaging"],"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"}