juicedata/juicefs · error

failed to run command line: %s, %v

Error message

failed to run command line: %s, %v

What it means

On Windows, `getprocessCommandLine` queries a process's command line via `wmic process where ProcessID=<pid> get CommandLine`. If `wmic` fails to execute or exits non-zero, the full command and error are wrapped with this message; `getCmdMount` then fails and `juicefs debug` reports 'failed to get mount command'.

Source

Thrown at cmd/debug_windows.go:39

	"encoding/json"
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
	"time"

	"github.com/juicedata/juicefs/pkg/utils"
	"github.com/juicedata/juicefs/pkg/vfs"
	"golang.org/x/sys/windows"
)

func getprocessCommandLine(pid int) (string, error) {
	cmd := exec.Command("wmic", "process", "where", "ProcessID="+strconv.Itoa(pid), "get", "CommandLine")
	out, err := cmd.CombinedOutput()
	if err != nil {
		return "", fmt.Errorf("failed to run command line: %s, %v", cmd.String(), err)
	}

	lines := strings.Split(string(out), "\r\n")
	if len(lines) < 2 {
		return "", fmt.Errorf("failed to find command line for pid: %d", pid)
	}

	for _, line := range lines[1:] {
		sline := strings.TrimSpace(line)
		if sline == "" {
			continue
		}
		return sline, nil
	}

	return "", fmt.Errorf("cannot find command line for pid %d. If the juicefs are mounted at background, Please rerun this with the admin permission.", pid)
}

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Verify WMIC availability: `wmic /?` in cmd; if removed, install the WMIC feature or use an environment where it exists.
  2. Re-run `juicefs debug` to rule out a pid-exit race.
  3. As a workaround, get the command line via PowerShell: `(Get-CimInstance Win32_Process -Filter "ProcessId=<pid>").CommandLine`.
  4. Check PATH includes `C:\Windows\System32\wbem` where wmic resides.

Example fix

// before (wmic removed on Win11 24H2)
PS> juicefs debug Z:\
failed to run command line: wmic process ... : exec: "wmic": executable file not found
// after (manual check via PowerShell)
PS> (Get-CimInstance Win32_Process -Filter "ProcessId=1234").CommandLine
Defensive patterns

Strategy: validation

Validate before calling

if _, err := exec.LookPath("wmic"); err != nil {
  return fmt.Errorf("wmic unavailable; use PowerShell Get-CimInstance instead")
}

Type guard

null

Try / catch

err := runDebug(mp)
if err != nil && strings.Contains(err.Error(), "failed to run command line") {
  // wmic missing or pid exited; fall back to Get-CimInstance query and retry
}

Prevention

When it happens

Trigger: Running `juicefs debug <mp>` on Windows when `wmic` is absent (removed in Windows 11 newer builds), not on PATH, blocked by policy, or fails for the pid (e.g. the pid exited between enumeration and the wmic query).

Common situations: Windows 11 24H2+ where wmic is deprecated/removed; enterprise policy disabling WMIC; debugging a mount process that just exited; running from a shell without the System32 path in PATH.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/8585130a3a345a1c. Report an issue: GitHub.