jdx/mise · error

user service ' ': the command contains , which cmd.exe…

Error message

user service '{}': the command contains {c:?}, which cmd.exe would reinterpret when `environment` is set; move it into a script

What it means

When `environment` is set, the service command line itself goes through cmd.exe, so characters cmd.exe treats specially (% expansion, &, |, <, >, ^, newlines) would split, chain, or rewrite the command rather than run it literally. exec_action rejects such commands instead of silently changing their meaning.

Solutions

  1. Move the complex command into a .cmd/.ps1 script and point the service at the script
  2. Remove the special characters or quote/escape them so cmd.exe does not reinterpret them
  3. Avoid setting `environment` if the command only works as a direct (non-cmd) invocation

Example fix

// before
program: "app.exe", args: ["--flag", "a&b"], environment: {"X": "1"}
// after
program: "C:\\scripts\\run-app.cmd" // script handles 'a&b' safely
Defensive patterns

Strategy: validation

Validate before calling

if (Object.keys(svc.environment).length) {
  const cmd = [svc.program, ...svc.args].join(' ');
  const c = [...cmd].find(c => '%&|<>^\r\n'.includes(c));
  if (c) throw new Error(`command contains cmd.exe metacharacter ${c}; use a script`);
}

Type guard

function isCmdSafeCommand(cmd) { return ![...cmd].some(c => '%&|<>^\r\n'.includes(c)); }

Try / catch

try { renderServiceXml(svc); } catch (e) { if (String(e).includes('move it into a script')) { wrapInScript(svc); } else throw e; }

Prevention

When it happens

Trigger: render_xml -> exec_action on Windows where request.environment is non-empty AND the composed "{program} {args}" string contains '%', '&', '|', '<', '>', '^', '\n', or '\r'.

Common situations: Commands like `foo.exe a & b` or arguments containing '%VAR%' that worked without env injection; multi-line commands pasted into a config; arguments with regex '^' anchors.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/a61ad80f1aeebc93. Report an issue: GitHub.

Appendix: source

Thrown at src/system/scheduled_tasks.rs:233

        }
        if let Some(c) = value
            .chars()
            .find(|c| matches!(c, '"' | '%' | '&' | '|' | '<' | '>' | '^' | '\n' | '\r'))
        {
            bail!(
                "user service '{}': environment value for {key} contains {c:?}, which cmd.exe would reinterpret; set it inside the program instead",
                request.name
            );
        }
        sets.push(format!("set \"{key}={value}\""));
    }
    // the command line goes through cmd.exe too: what it would split or
    // chain is rejected the same way, rather than run differently
    if let Some(c) = format!("{program} {args}")
        .chars()
        .find(|c| matches!(c, '%' | '&' | '|' | '<' | '>' | '^' | '\n' | '\r'))
    {
        bail!(
            "user service '{}': the command contains {c:?}, which cmd.exe would reinterpret when `environment` is set; move it into a script",
            request.name
        );
    }
    let program = if program.contains(char::is_whitespace) {
        format!("\"{program}\"")
    } else {
        program
    };
    let rest = if args.is_empty() {
        program
    } else {
        format!("{program} {args}")
    };
    Ok((
        "cmd.exe".to_string(),
        format!("/c {} && {rest}", sets.join(" && ")),
    ))

View on GitHub (pinned to 533346cc37)