nodejsscript • Docs
nodejsscript / s / 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);
String of command(s) to be executed. Defined patterns (by default /::([^:]+)::/g
) will be replaced by actual value.
Arguments for command
.
Silence and synchronous options.
run(
command
,vars
?):ShellString
• 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 an object containing the return code and output as ShellString.
String of command(s) to be executed. Defined patterns (by default /::([^:]+)::/g
) will be replaced by actual value.
Arguments for command
.
Silence and synchronous options.
run(
command
,vars
,options
):ShellString
• 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 an object containing the return code and output as ShellString.
String of command(s) to be executed. Defined patterns (by default /::([^:]+)::/g
) will be replaced by actual value.
Arguments for command
.
Silence and synchronous options.