Skip to content

Latest commit

 

History

History
122 lines (75 loc) · 2.87 KB

File metadata and controls

122 lines (75 loc) · 2.87 KB

nodejsscriptDocs


nodejsscript / s / run

Function: run()

You can use this function to run executable commands not listed in the shelljs (s namespace). For example (the simplest one):

s.run`git branch --show-current`;

…you can also pass variables and function automatically escapes them.

const var= "Hello World";
s.run`echo ${var}`;

…alternatively you can use classic function approach:

s.run("echo ::var::", { var: "Hello World" });

…this way you can also pass additional options:

s.run("echo 'HI'", null, { cwd: "../" });
s.run("echo ::var::", { var: "Hi" }, { cwd: "../" });

Internally the child_process.execFileSync is used to execute the command, so use any of the options supported by that function.

By default the function prints the output of the command to stdout. You can use $.is_silent= false or s.$:

const branch= s.$().run`git branch --show-current`.stdout;
echo(branch);

Param

String of command(s) to be executed. Defined patterns (by default /::([^:]+)::/g) will be replaced by actual value.

Param

Arguments for command.

Param

Silence and synchronous options.

run(command, vars)

run(command, vars?): ShellString

Parameters

command: string

String of command(s) to be executed. Defined patterns (by default /::([^:]+)::/g) will be replaced by actual value.

vars?

Arguments for command.

Returns

ShellString

Returns ShellString.

Returns an object containing the return code and output as ShellString.

Param

String of command(s) to be executed. Defined patterns (by default /::([^:]+)::/g) will be replaced by actual value.

Param

Arguments for command.

Param

Silence and synchronous options.

run(command, vars, options)

run(command, vars, options): ShellString

Parameters

command: string

String of command(s) to be executed. Defined patterns (by default /::([^:]+)::/g) will be replaced by actual value.

vars: false | object

Arguments for command.

options: RunOptions

Silence and options.

Returns

ShellString

Returns ShellString.

Returns an object containing the return code and output as ShellString.

Param

String of command(s) to be executed. Defined patterns (by default /::([^:]+)::/g) will be replaced by actual value.

Param

Arguments for command.

Param

Silence and synchronous options.