diff --git a/shelljs/shelljs-tests.ts b/shelljs/shelljs-tests.ts index d28b72398..835f177a6 100644 --- a/shelljs/shelljs-tests.ts +++ b/shelljs/shelljs-tests.ts @@ -85,8 +85,34 @@ shell.ln("-sf", "file", "existing"); var testPath = shell.env["path"]; +import child = require("child_process"); + var version = shell.exec("node --version").output; +var version2 = shell.exec("node --version", { async: false }); +var output = version2.output; + +var asyncVersion3 = shell.exec("node --version", { async: true }); +var pid = asyncVersion3.pid; + +shell.exec("node --version", { silent: true }, function (code, output) { + var version = output; +}); +shell.exec("node --version", { silent: true, async: true }, function (code, output) { + var version = output; +}); +shell.exec("node --version", function (code, output) { + var version = output; +}); +shell.exec("node --version", function (code: number) { + var num: number = code; +}); + +var childProc = shell.exec("node --version", function (code: number) { + var num: number = code; +}); +var pid = childProc.pid; + shell.chmod(755, "/Users/brandon"); shell.chmod("755", "/Users/brandon"); // same as above shell.chmod("u+x", "/Users/brandon"); diff --git a/shelljs/shelljs.d.ts b/shelljs/shelljs.d.ts index b3b732d05..c4608caee 100644 --- a/shelljs/shelljs.d.ts +++ b/shelljs/shelljs.d.ts @@ -8,6 +8,8 @@ declare module "shelljs" { + import child = require("child_process"); + /** * Changes to directory dir for the duration of the script * @param {string} dir Directory to change in. @@ -434,31 +436,44 @@ declare module "shelljs" * Object containing environment variables (both getter and setter). Shortcut to process.env. */ export var env: { [key: string]: string }; - - /* - - // Not yet implemented due to implementation issues (constant overloads and return types). - // See: https://github.com/arturadib/shelljs#execcommand--options--callback - - export function exec(command: string, options: ExecOptions, callback: (code: number, output: string) => any): any; - export function exec(command: string, options: ExecOptions): any; - - interface ExecOptions - { - silent: boolean; - async: boolean; - } - - */ - + /** * Executes the given command synchronously. - * @param {string} command The commadn to execute. - * @return {ExecReturnValue} Returns an object containing the return code and output as string. + * @param {string} command The command to execute. + * @return {ExecOutputReturnValue} Returns an object containing the return code and output as string. */ - export function exec(command: string): ExecReturnValue; + export function exec(command: string): ExecOutputReturnValue; + /** + * Executes the given command synchronously. + * @param {string} command The command to execute. + * @param {ExecOptions} options Silence and synchronous options. + * @return {ExecOutputReturnValue | child.ChildProcess} Returns an object containing the return code and output as string, or if {async:true} was passed, a ChildProcess. + */ + export function exec(command: string, options: ExecOptions): ExecOutputReturnValue | child.ChildProcess; + /** + * Executes the given command synchronously. + * @param {string} command The command to execute. + * @param {ExecOptions} options Silence and synchronous options. + * @param {ExecCallback} callback Receives code and output asynchronously. + */ + export function exec(command: string, options: ExecOptions, callback: ExecCallback): child.ChildProcess; + /** + * Executes the given command synchronously. + * @param {string} command The command to execute. + * @param {ExecCallback} callback Receives code and output asynchronously. + */ + export function exec(command: string, callback: ExecCallback): child.ChildProcess; - interface ExecReturnValue + export interface ExecCallback { + (code: number, output: string): any; + } + + export interface ExecOptions { + silent?: boolean; + async?: boolean; + } + + export interface ExecOutputReturnValue { code: number; output: string;