Yalantis/uCrop · warning

cimg::system() : Command '%s' (module name '%s) failed with

Error message

cimg::system() : Command '%s' (module name '%s) failed with error %lu: %s

What it means

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.

Source

Thrown at ucrop/src/main/jni/CImg.h:6022

      std::memset(&si,0,sizeof(STARTUPINFO));
      GetStartupInfoA(&si);
      si.cb = sizeof(si);
      si.wShowWindow = SW_HIDE;
      si.dwFlags |= SW_HIDE | STARTF_USESHOWWINDOW;
      const BOOL res = CreateProcessA((LPCSTR)module_name,(LPSTR)command,0,0,FALSE,0,0,0,&si,&pi);
      if (res) {
        WaitForSingleObject(pi.hProcess,INFINITE);
        CloseHandle(pi.hThread);
        CloseHandle(pi.hProcess);
        return 0;
      } else {
        char* lpMsgBuf;

        // Get the error message.
        DWORD errorCode = GetLastError();
        FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                       0,errorCode,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPSTR)&lpMsgBuf,0,0);
        cimg::warn("cimg::system() : Command '%s' (module name '%s) failed with error %lu: %s",
                   module_name==0?"(null)":module_name,
                   command==0?"(null)":command,
                   errorCode,lpMsgBuf);
        return -1;
      }
#else
      return std::system(command);
#endif
#endif
    }

    //! Return a reference to a temporary variable of type T.
    template<typename T>
    inline T& temporary(const T&) {
      static T temp;
      return temp;
    }

View on GitHub (pinned to f788b534b4)

Solutions

  1. Verify the command's executable is installed and present in PATH on the target Windows machine
  2. Print/inspect the exact command string being built (check quoting of paths with spaces)
  3. Handle the -1 return value instead of assuming success, and provide a fallback path that does not shell out
  4. Run the same command manually in cmd.exe to see the underlying OS error

Example fix

// before
cimg::system("convert in.png out.jpg", true);
// after
const int res = cimg::system("\"C:\\Program Files\\ImageMagick\\convert.exe\" in.png out.jpg", true);
if (res != 0) { /* fallback: use CImg's native load/save instead */ }
Defensive patterns

Strategy: fallback

Validate before calling

// before shelling out
const char* cmd = "convert";
if (!cmd || !*cmd) { fprintf(stderr, "no command configured\n"); return; }
// On Windows, optionally check availability:
// cimg::system("where convert >nul 2>&1") != 0 -> command missing

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/b3b2fd61b21a4e4c. Report an issue: GitHub.