{"record":{"id":"b3b2fd61b21a4e4c","repo":"Yalantis/uCrop","slug":"cimg-system-command-s-module-name-s-fa","errorCode":null,"errorMessage":"cimg::system() : Command '%s' (module name '%s) failed with error %lu: %s","messagePattern":"cimg::system\\(\\) : Command '(.+?)' \\(module name '(.+?)\\) failed with error %lu: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":6022,"sourceCode":"      std::memset(&si,0,sizeof(STARTUPINFO));\n      GetStartupInfoA(&si);\n      si.cb = sizeof(si);\n      si.wShowWindow = SW_HIDE;\n      si.dwFlags |= SW_HIDE | STARTF_USESHOWWINDOW;\n      const BOOL res = CreateProcessA((LPCSTR)module_name,(LPSTR)command,0,0,FALSE,0,0,0,&si,&pi);\n      if (res) {\n        WaitForSingleObject(pi.hProcess,INFINITE);\n        CloseHandle(pi.hThread);\n        CloseHandle(pi.hProcess);\n        return 0;\n      } else {\n        char* lpMsgBuf;\n\n        // Get the error message.\n        DWORD errorCode = GetLastError();\n        FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\n                       0,errorCode,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPSTR)&lpMsgBuf,0,0);\n        cimg::warn(\"cimg::system() : Command '%s' (module name '%s) failed with error %lu: %s\",\n                   module_name==0?\"(null)\":module_name,\n                   command==0?\"(null)\":command,\n                   errorCode,lpMsgBuf);\n        return -1;\n      }\n#else\n      return std::system(command);\n#endif\n#endif\n    }\n\n    //! Return a reference to a temporary variable of type T.\n    template<typename T>\n    inline T& temporary(const T&) {\n      static T temp;\n      return temp;\n    }\n","sourceCodeStart":6004,"sourceCodeEnd":6040,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L6004-L6040","documentation":"cimg::system() runs an external shell command; on Windows it uses system()/popen-style helpers and reports failure via GetLastError(). When the command returns nonzero, CImg emits this warning with the OS error message from FormatMessageA and returns -1 instead of throwing. It signals that the requested external program could not be launched or executed by the OS.","triggerScenarios":"Calling cimg::system() (directly or indirectly via CImg features that shell out, e.g. external viewer/convert helpers) on Windows when the command binary is missing from PATH, is misspelled, or exits with a nonzero status; module_name or command may even be null as handled in the source.","commonSituations":"Windows deployments where ImageMagick/ffmpeg or a viewer executable is not installed or not on PATH; quoting problems with paths containing spaces; environment differences between dev and target machines.","solutions":["Verify the command's executable is installed and present in PATH on the target Windows machine","Print/inspect the exact command string being built (check quoting of paths with spaces)","Handle the -1 return value instead of assuming success, and provide a fallback path that does not shell out","Run the same command manually in cmd.exe to see the underlying OS error"],"exampleFix":"// before\ncimg::system(\"convert in.png out.jpg\", true);\n// after\nconst int res = cimg::system(\"\\\"C:\\\\Program Files\\\\ImageMagick\\\\convert.exe\\\" in.png out.jpg\", true);\nif (res != 0) { /* fallback: use CImg's native load/save instead */ }","handlingStrategy":"fallback","validationCode":"// before shelling out\nconst char* cmd = \"convert\";\nif (!cmd || !*cmd) { fprintf(stderr, \"no command configured\\n\"); return; }\n// On Windows, optionally check availability:\n// cimg::system(\"where convert >nul 2>&1\") != 0 -> command missing","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ship full paths to external executables instead of relying on PATH","Quote every path argument to survive spaces","Check the int return value of cimg::system() for -1 and log the command string"],"tags":["cimg","windows","external-process"],"backgroundTag":"command-execution-failed","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"}