Skip to main content
Module

x/denops_std/function/mod.ts>system

📚 Standard module for denops.vim
Go to Latest
function system
import { system } from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";

Get the output of the shell command {expr} as a String. See systemlist() to get the output as a List.

When {input} is given and is a String this string is written to a file and passed as stdin to the command. The string is written as-is, you need to take care of using the correct line separators yourself. If {input} is given and is a List it is written to the file in a way writefile() does with {binary} set to "b" (i.e. with a newline between each list item with newlines inside list items converted to NULs). When {input} is given and is a number that is a valid id for an existing buffer then the content of the buffer is written to the file line by line, each line terminated by a NL and NULs characters where the text has a NL.

Pipes are not used, the 'shelltemp' option is not used.

When prepended by :silent the terminal will not be set to cooked mode. This is meant to be used for commands that do not need the user to type. It avoids stray characters showing up on the screen which require CTRL-L to remove.

:silent let f = system('ls *.vim')

Note: Use shellescape() or ::S with expand() or fnamemodify() to escape special characters in a command argument. Newlines in {expr} may cause the command to fail. The characters in 'shellquote' and 'shellxquote' may also cause trouble. This is not to be used for interactive commands.

The result is a String. Example:

:let files = system('ls ' .. shellescape(expand('%:h')))
:let files = system('ls ' .. expand('%:h:S'))

To make the result more system-independent, the shell output is filtered to replace <CR> with <NL> for Macintosh, and <CR><NL> with <NL> for DOS-like systems. To avoid the string being truncated at a NUL, all NUL characters are replaced with SOH (0x01).

The command executed is constructed using several options: 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote' ({tmp} is an automatically generated file name). For Unix, braces are put around {expr} to allow for concatenated commands.

The command will be executed in "cooked" mode, so that a CTRL-C will interrupt the command (on Unix at least).

The resulting error code can be found in v:shell_error. This function will fail in restricted-mode.

Note that any wrong value in the options mentioned above may make the function fail. It has also been reported to fail when using a security agent application. Unlike ":!cmd" there is no automatic check for changed files. Use :checktime to force a check.

Can also be used as a method:

:echo GetCmd()->system()

Parameters

denops: Denops
expr: unknown
optional
input: unknown

Returns

Promise<string>