当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ChildProcess.once方法代码示例

本文整理汇总了TypeScript中child_process.ChildProcess.once方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ChildProcess.once方法的具体用法?TypeScript ChildProcess.once怎么用?TypeScript ChildProcess.once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在child_process.ChildProcess的用法示例。


在下文中一共展示了ChildProcess.once方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: handleProcess

function handleProcess(event: string, childProcess: ChildProcess, command: string, resolve: ((value?: any) => void) | null, reject: (reason?: any) => void) {
  childProcess.on("error", reject)

  let out = ""
  if (childProcess.stdout != null) {
    childProcess.stdout.on("data", (data: string) => {
      out += data
    })
  }

  let errorOut = ""
  if (childProcess.stderr != null) {
    childProcess.stderr.on("data", (data: string) => {
      errorOut += data
    })
  }

  childProcess.once(event, (code: number) => {
    if (log.isDebugEnabled) {
      const fields: any = {
        command: path.basename(command),
        code,
        pid: childProcess.pid,
      }
      if (out.length > 0) {
        fields.out = out
      }
      log.debug(fields, "exited")
    }

    if (code === 0) {
      if (resolve != null) {
        resolve(out)
      }
    }
    else {
      function formatOut(text: string, title: string) {
        return text.length === 0 ? "" : `\n${title}:\n${text}`
      }

      reject(new Error(`${command} exited with code ${code}${formatOut(out, "Output")}${formatOut(errorOut, "Error output")}`))
    }
  })
}
开发者ID:electron-userland,项目名称:electron-builder,代码行数:44,代码来源:util.ts

示例2: startDebugSession

export function startDebugSession(debuggerType: DebuggerType, debuggerFilename?: string): DebugSession {
  let debuggerArgs: string[];

  switch (debuggerType) {
    case DebuggerType.LLDB:
      setProcessEnvironment();
      if (!debuggerFilename) {
        // lldb-mi.exe should be on the PATH
        debuggerFilename = 'lldb-mi';
      }
      debuggerArgs = ['--interpreter'];
      break;

    case DebuggerType.GDB:
      if (!debuggerFilename) {
        debuggerFilename = 'gdb';
      }
      debuggerArgs = ['--interpreter', 'mi'];
      break;

    default:
      throw new Error('Unknown debugger type!');
  }

  const debuggerProcess: ChildProcess = spawn(debuggerFilename, debuggerArgs);
  let debugSession: DebugSession = null;
  if (debuggerProcess) {
    if (debuggerType === DebuggerType.GDB) {
      debugSession = new GDBDebugSession(debuggerProcess.stdout, debuggerProcess.stdin);
    } else {
      debugSession = new DebugSession(debuggerProcess.stdout, debuggerProcess.stdin);
    }
    if (debugSession) {
      debuggerProcess.once('exit',
        (code: number, signal: string) => { debugSession.end(false); }
      );
    }
  }
  return debugSession;
};
开发者ID:ASMImproved,项目名称:dbgmits,代码行数:40,代码来源:dbgmits.ts

示例3: handleProcess

export function handleProcess(event: string, childProcess: ChildProcess, command: string, resolve: ((value?: any) => void) | null, reject: (reason?: any) => void) {
  childProcess.on("error", reject)

  let out = ""
  if (!debug.enabled && childProcess.stdout != null) {
    childProcess.stdout.on("data", (data: string) => {
      out += data
    })
  }

  let errorOut = ""
  if (childProcess.stderr != null) {
    childProcess.stderr.on("data", (data: string) => {
      errorOut += data
    })
  }

  childProcess.once(event, (code: number) => {
    if (code === 0 && debug.enabled) {
      debug(`${path.basename(command)} (${childProcess.pid}) exited with exit code 0`)
    }

    if (code === 0) {
      if (resolve != null) {
        resolve()
      }
    }
    else {
      function formatOut(text: string, title: string) {
        return text.length === 0 ? "" : `\n${title}:\n${text}`
      }

      reject(new Error(`${command} exited with code ${code}${formatOut(out, "Output")}${formatOut(errorOut, "Error output")}`))
    }
  })
}
开发者ID:jwheare,项目名称:electron-builder,代码行数:36,代码来源:util.ts

示例4: Promise

  let promise = new Promise((resolve, reject) => {
    let { ignoreStdio, ...nodeOptions } = options;
    // @ts-ignore: cross-spawn declares "args" to be a regular array instead of a read-only one
    child = spawn(command, args, nodeOptions);
    let stdout = '';
    let stderr = '';

    if (!ignoreStdio) {
      if (child.stdout) {
        child.stdout.on('data', data => {
          stdout += data;
        });
      }

      if (child.stderr) {
        child.stderr.on('data', data => {
          stderr += data;
        });
      }
    }

    let completionListener = (code: number | null, signal: string | null) => {
      child.removeListener('error', errorListener);
      let result: SpawnResult = {
        pid: child.pid,
        output: [stdout, stderr],
        stdout,
        stderr,
        status: code,
        signal,
      };
      if (code !== 0) {
        let error = signal
          ? new Error(`${command} exited with signal: ${signal}`)
          : new Error(`${command} exited with non-zero code: ${code}`);
        if (error.stack && previousStackString) {
          error.stack += `\n${previousStackString}`
        }
        Object.assign(error, result);
        reject(error);
      } else {
        resolve(result);
      }
    };

    let errorListener = (error: Error) => {
      if (ignoreStdio) {
        child.removeListener('exit', completionListener);
      } else {
        child.removeListener('close', completionListener);
      }
      Object.assign(error, {
        pid: child.pid,
        output: [stdout, stderr],
        stdout,
        stderr,
        status: null,
        signal: null,
      });
      reject(error);
    };

    if (ignoreStdio) {
      child.once('exit', completionListener);
    } else {
      child.once('close', completionListener);
    }
    child.once('error', errorListener);
  }) as SpawnPromise<SpawnResult>;
开发者ID:exponentjs,项目名称:spawn-async,代码行数:69,代码来源:spawnAsync.ts


注:本文中的child_process.ChildProcess.once方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。