最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

需要的NodeJS“child

IT培训 admin 8浏览 0评论

需要的NodeJS“child

我工作的一个简单的NodeJS electron(原名原子壳)项目。我使用的角度写2它,使用与项目相同的项目设置,因为他们为打字稿的文档中建议:

TSK:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
  "node_modules",
  "typings/main",
  "typings/main.d.ts"
  ]
}

我需要运行一个命令,我发现我可以用节点“child_process”做到这一点。我无论如何也找不到对我来说,“进口”或“要求”它同时具有从node.d.ts文件中使用它的类型。我发现其中适合我的需要node.d.ts文件中的“child_process”的界面,这是怎么看在node.d.ts文件:

    declare module "child_process" {
    import * as events from "events";
    import * as stream from "stream";

    export interface ChildProcess extends events.EventEmitter {
        stdin:  stream.Writable;
        stdout: stream.Readable;
        stderr: stream.Readable;
        pid: number;
        kill(signal?: string): void;
        send(message: any, sendHandle?: any): void;
        disconnect(): void;
        unref(): void;
    }

    export function spawn(command: string, args?: string[], options?: {
        cwd?: string;
        stdio?: any;
        custom?: any;
        env?: any;
        detached?: boolean;
    }): ChildProcess;
    export function exec(command: string, options: {
        cwd?: string;
        stdio?: any;
        customFds?: any;
        env?: any;
        encoding?: string;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
    }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function execFile(file: string,
        callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function execFile(file: string, args?: string[],
        callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function execFile(file: string, args?: string[], options?: {
        cwd?: string;
        stdio?: any;
        customFds?: any;
        env?: any;
        encoding?: string;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
    }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function fork(modulePath: string, args?: string[], options?: {
        cwd?: string;
        env?: any;
        execPath?: string;
        execArgv?: string[];
        silent?: boolean;
        uid?: number;
        gid?: number;
    }): ChildProcess;
    export function spawnSync(command: string, args?: string[], options?: {
        cwd?: string;
        input?: string | Buffer;
        stdio?: any;
        env?: any;
        uid?: number;
        gid?: number;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
        encoding?: string;
    }): {
        pid: number;
        output: string[];
        stdout: string | Buffer;
        stderr: string | Buffer;
        status: number;
        signal: string;
        error: Error;
    };
    export function execSync(command: string, options?: {
        cwd?: string;
        input?: string|Buffer;
        stdio?: any;
        env?: any;
        uid?: number;
        gid?: number;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
        encoding?: string;
    }): string | Buffer;
    export function execFileSync(command: string, args?: string[], options?: {
        cwd?: string;
        input?: string|Buffer;
        stdio?: any;
        env?: any;
        uid?: number;
        gid?: number;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
        encoding?: string;
    }): string | Buffer;
}

但我只能(我知道的),只能通过进口获得此类型:

import * as child_process from 'child_process'; 

唯一的问题是,当我这样做,我的应用程序加载斜面和我在控制台收到以下错误:

GET file:///C:/angular2Samples/NGW-electron-VS%20-%20TEMP/child_process net::ERR_FILE_NOT_FOUND

现在,即时通讯使用避过我的方式:

var child_process = require('child_process');

但我找不到反正类型的信息添加到该变种:

var child_process : I_CANT_PUT_ANY_CHILD_PROCESS_TYPE_HERE = require('child_process');

同类型的信息:我如何能得到child_process(“”经营者或公众的arent接口,我可以说出后,任何其他声明的节点模块)任何想法?

非常感谢提前任何帮助和解释:)

UPDATE ------------------------------------------------- -----------------

作为tenbits建议我已经添加了参考如下的文件的顶部:///

并用你说的进口statment,但没有恰克我模块加载。它仍然没有工作,用同样的错误预期。我不是感觉很舒服有关更改模块系统,为我的项目使用角2和他们的文档和他们的一些导游说,这之前没有prefernce此事(新项目,我是很新的模块装载机现场和IM不充分了解它是如何工作还)。当我试图去改变它我就2分的东西,我没有足够的时间进入目前一些错误。不应该有一种方法来此不改变模块加载器?通过在systemjs现场一眼它说在它支持CommonJS的模块开始:Systemjs doc

我真的认为并欣赏不改变模块系统的解决方案,或者可能对正在发生的事情和一个更深入explanition接近这些类型的模块加载问题存在在那里

回答如下:

好了,经过一番研究#L138我已经找到了解决方案

您可以使用import像以前一样

import * as child from 'child_process';

var foo: child.ChildProcess = child.exec('foo.sh');
console.log(typeof foo.on);

但是,你应该配置SystemJS到模块NodeJS映射。

System.config({
  map: {
    'child_process': '@node/child_process'
  }
});

而已!

需要的NodeJS“child

我工作的一个简单的NodeJS electron(原名原子壳)项目。我使用的角度写2它,使用与项目相同的项目设置,因为他们为打字稿的文档中建议:

TSK:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
  "node_modules",
  "typings/main",
  "typings/main.d.ts"
  ]
}

我需要运行一个命令,我发现我可以用节点“child_process”做到这一点。我无论如何也找不到对我来说,“进口”或“要求”它同时具有从node.d.ts文件中使用它的类型。我发现其中适合我的需要node.d.ts文件中的“child_process”的界面,这是怎么看在node.d.ts文件:

    declare module "child_process" {
    import * as events from "events";
    import * as stream from "stream";

    export interface ChildProcess extends events.EventEmitter {
        stdin:  stream.Writable;
        stdout: stream.Readable;
        stderr: stream.Readable;
        pid: number;
        kill(signal?: string): void;
        send(message: any, sendHandle?: any): void;
        disconnect(): void;
        unref(): void;
    }

    export function spawn(command: string, args?: string[], options?: {
        cwd?: string;
        stdio?: any;
        custom?: any;
        env?: any;
        detached?: boolean;
    }): ChildProcess;
    export function exec(command: string, options: {
        cwd?: string;
        stdio?: any;
        customFds?: any;
        env?: any;
        encoding?: string;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
    }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function execFile(file: string,
        callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function execFile(file: string, args?: string[],
        callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function execFile(file: string, args?: string[], options?: {
        cwd?: string;
        stdio?: any;
        customFds?: any;
        env?: any;
        encoding?: string;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
    }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
    export function fork(modulePath: string, args?: string[], options?: {
        cwd?: string;
        env?: any;
        execPath?: string;
        execArgv?: string[];
        silent?: boolean;
        uid?: number;
        gid?: number;
    }): ChildProcess;
    export function spawnSync(command: string, args?: string[], options?: {
        cwd?: string;
        input?: string | Buffer;
        stdio?: any;
        env?: any;
        uid?: number;
        gid?: number;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
        encoding?: string;
    }): {
        pid: number;
        output: string[];
        stdout: string | Buffer;
        stderr: string | Buffer;
        status: number;
        signal: string;
        error: Error;
    };
    export function execSync(command: string, options?: {
        cwd?: string;
        input?: string|Buffer;
        stdio?: any;
        env?: any;
        uid?: number;
        gid?: number;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
        encoding?: string;
    }): string | Buffer;
    export function execFileSync(command: string, args?: string[], options?: {
        cwd?: string;
        input?: string|Buffer;
        stdio?: any;
        env?: any;
        uid?: number;
        gid?: number;
        timeout?: number;
        maxBuffer?: number;
        killSignal?: string;
        encoding?: string;
    }): string | Buffer;
}

但我只能(我知道的),只能通过进口获得此类型:

import * as child_process from 'child_process'; 

唯一的问题是,当我这样做,我的应用程序加载斜面和我在控制台收到以下错误:

GET file:///C:/angular2Samples/NGW-electron-VS%20-%20TEMP/child_process net::ERR_FILE_NOT_FOUND

现在,即时通讯使用避过我的方式:

var child_process = require('child_process');

但我找不到反正类型的信息添加到该变种:

var child_process : I_CANT_PUT_ANY_CHILD_PROCESS_TYPE_HERE = require('child_process');

同类型的信息:我如何能得到child_process(“”经营者或公众的arent接口,我可以说出后,任何其他声明的节点模块)任何想法?

非常感谢提前任何帮助和解释:)

UPDATE ------------------------------------------------- -----------------

作为tenbits建议我已经添加了参考如下的文件的顶部:///

并用你说的进口statment,但没有恰克我模块加载。它仍然没有工作,用同样的错误预期。我不是感觉很舒服有关更改模块系统,为我的项目使用角2和他们的文档和他们的一些导游说,这之前没有prefernce此事(新项目,我是很新的模块装载机现场和IM不充分了解它是如何工作还)。当我试图去改变它我就2分的东西,我没有足够的时间进入目前一些错误。不应该有一种方法来此不改变模块加载器?通过在systemjs现场一眼它说在它支持CommonJS的模块开始:Systemjs doc

我真的认为并欣赏不改变模块系统的解决方案,或者可能对正在发生的事情和一个更深入explanition接近这些类型的模块加载问题存在在那里

回答如下:

好了,经过一番研究#L138我已经找到了解决方案

您可以使用import像以前一样

import * as child from 'child_process';

var foo: child.ChildProcess = child.exec('foo.sh');
console.log(typeof foo.on);

但是,你应该配置SystemJS到模块NodeJS映射。

System.config({
  map: {
    'child_process': '@node/child_process'
  }
});

而已!

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论