Skip to main content
Module

x/denops_std/function/vim/mod.ts>job_start

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

Start a job and return a Job object. Unlike system() and :!cmd this does not wait for the job to finish. To start a job in a terminal window see term_start().

If the job fails to start then job_status() on the returned Job object results in "fail" and none of the callbacks will be invoked.

{command} can be a String. This works best on MS-Windows. On Unix it is split up in white-separated parts to be passed to execvp(). Arguments in double quotes can contain white space.

{command} can be a List, where the first item is the executable and further items are the arguments. All items are converted to String. This works best on Unix.

On MS-Windows, job_start() makes a GUI application hidden. If you want to show it, use :!start instead.

The command is executed directly, not through a shell, the 'shell' option is not used. To use the shell:

let job = job_start(["/bin/sh", "-c", "echo hello"])

Or:

let job = job_start('/bin/sh -c "echo hello"')

Note that this will start two processes, the shell and the command it executes. If you don't want this use the "exec" shell command.

On Unix $PATH is used to search for the executable only when the command does not contain a slash.

The job will use the same terminal as Vim. If it reads from stdin the job and Vim will be fighting over input, that doesn't work. Redirect stdin and stdout to avoid problems:

let job = job_start(['sh', '-c', "myserver </dev/null >/dev/null"])

The returned Job object can be used to get the status with job_status() and stop the job with job_stop().

Note that the job object will be deleted if there are no references to it. This closes the stdin and stderr, which may cause the job to fail with an error. To avoid this keep a reference to the job. Thus instead of:

call job_start('my-command')

use:

let myjob = job_start('my-command')

and unlet "myjob" once the job is not needed or is past the point where it would fail (e.g. when it prints a message on startup). Keep in mind that variables local to a function will cease to exist if the function returns. Use a script-local variable if needed:

let s:myjob = job_start('my-command')

{options} must be a Dictionary. It can contain many optional items, see job-options.

Can also be used as a method:

BuildCommand()->job_start()

Parameters

denops: Denops
command: unknown
optional
options: unknown

Returns

Promise<unknown>