Skip to content

Shell API ​

File revelation, associated program execution, and external process management.

Shell API ​

shell.exec ​

Start a process from a command line and return at once; nothing is waited for. Commands are not allow-listed: a theme is trusted like an installed component. cwd goes through path security.

ParameterTypeRequiredDescription
commandstringYesCommand line, run as given. Must not be empty.
argsstring[]NoArguments appended to the command line, each quoted.
cwdstringNoWorking directory; the process inherits foobar2000's when omitted or empty.
hiddenbooleanNoStart the process without a visible window. Default: true.

Returns

FieldTypeDescription
processIdintegerWindows process id of the started process.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

Security Boundaries

shell.exec does not enforce an executable allowlist (themes are trusted under the same security boundary as native foobar2000 components). If cwd is supplied, the host performs path validation and rejects paths crossing directory boundaries. For destructive filesystem operations, prefer the file.* APIs which are protected by path blacklists.

Invocation Semantics

shell.exec uses fire-and-forget semantics: a successful call indicates only that the underlying process was created, not that the external command or service is fully initialized or completed.

js
await fb2k.invoke('shell.exec', {
	command: 'ffprobe',
	args: ['-hide_banner', 'C:\\Music\\song.flac'],
});

shell.openExternal ​

Open an http://, https:// or mailto: URL with the default handler.

ParameterTypeRequiredDescription
urlstringYesURL to open; any other scheme fails with INVALID_PARAMS. Must not be empty.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
await fb2k.invoke('shell.openExternal', {
	url: 'https://www.foobar2000.org/',
});

shell.openWith ​

Open a file with the application Windows associates with its type. Executables, scripts, installers, shortcuts and libraries are refused with PERMISSION_DENIED.

ParameterTypeRequiredDescription
pathstringYesFile to hand to its associated application. Must not be empty.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
await fb2k.invoke('shell.openWith', { path: 'C:\\Music\\cover.jpg' });

shell.showInExplorer ​

Reveal a file or folder in Windows Explorer, selecting it.

ParameterTypeRequiredDescription
pathstringYesFile or folder to reveal. Must not be empty.

Returns

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

js
await fb2k.invoke('shell.showInExplorer', { path: 'C:\\Music\\song.flac' });

shell.spawn ​

Start a process from an executable and an argument list. With waitForExitMs the call waits that long for an early exit; a non-zero exit within the wait fails with OPERATION_FAILED and the failure carries processId, exited and exitCode. An absolute executable path and cwd go through path security.

ParameterTypeRequiredDescription
executablestringYesExecutable name (resolved through PATH) or path. Surrounding whitespace and quotes are removed. Must not be empty.
argsstring[]NoArguments passed to the process, each quoted.
cwdstringNoWorking directory, which has to exist; the process inherits foobar2000's when omitted or empty.
hiddenbooleanNoStart the process without a visible window. Default: true.
waitForExitMsintegerNoMilliseconds to wait for an early exit; 0 returns as soon as the process starts. At least 0. Default: 0.

Returns

FieldTypeDescription
processIdintegerWindows process id of the started process.
exitedbooleanWhether the process exited within waitForExitMs; absent when no wait was requested.
exitCodeintegerThe exit code, present when exited is true.

success is true on success. On failure the response is { success: false, error, code }; see Error codes for code.

Security Boundaries

shell.spawn does not restrict executable names (based on equal trust in theme authors). When passing an absolute executable path or cwd, the host performs path validation and rejects paths targeting protected directories.

js
const res = await fb2k.invoke('shell.spawn', {
	executable: 'ffprobe.exe',
	args: ['C:\\Music\\song.flac'],
	waitForExitMs: 5000,
});
if (res.success === false) throw new Error(res.error);
const { exited, exitCode } = res;

Shell boundaries ​

  • shell.openExternal accepts only http://, https://, or mailto: URLs. shell.openWith rejects executable, script, installer, shortcut, library, and related dangerous extensions.
  • shell.exec and shell.spawn intentionally do not impose a command allowlist. Their cwd and any absolute executable path are validated; shell.spawn.waitForExitMs optionally reports early process exit.