Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Npm NAnt exec命令混乱输出_Npm_Nant - Fatal编程技术网

Npm NAnt exec命令混乱输出

Npm NAnt exec命令混乱输出,npm,nant,Npm,Nant,当我执行从命令行调用npm的批处理文件时,我会看到格式良好的输出,例如: ├── interpret@0.3.10 ├── pretty-hrtime@0.2.2 ├── deprecated@0.0.1 ├── archy@1.0.0 ├── minimist@1.1.0 ├── tildify@1.0.0 (user-home@1.1.1) ├── semver@4.2.0 ├── v8flags@1.0.8 ├── chalk@0.5.1 (escape-string-regexp@1.0

当我执行从命令行调用npm的批处理文件时,我会看到格式良好的输出,例如:

├── interpret@0.3.10
├── pretty-hrtime@0.2.2
├── deprecated@0.0.1
├── archy@1.0.0
├── minimist@1.1.0
├── tildify@1.0.0 (user-home@1.1.1)
├── semver@4.2.0
├── v8flags@1.0.8
├── chalk@0.5.1 (escape-string-regexp@1.0.2, ansi-styles@1.1.0, support
├── orchestrator@0.3.7 (stream-consume@0.1.0, sequencify@0.0.7, end-of-
├── liftoff@0.13.6 (extend@1.3.0, flagged-respawn@0.3.1, resolve@1.0.0,
├── vinyl-fs@0.3.13 (graceful-fs@3.0.5, mkdirp@0.5.0, vinyl@0.4.6, defa
└── gulp-util@3.0.2 (object-assign@2.0.0, array-differ@1.0.0, array-uni
gh2@0.6.3, multipipe@0.1.2, lodash.template@2.4.1, dateformat@1.0.11)
StandardErrorEncoding = Encoding.UTF8
但是,当我使用exec任务从NAnt脚本调用同一批处理文件时,输出会变得混乱(即使我使用“output”开关将输出传输到文件):


是否有解决方法?

此行为是由NAnt
exec
任务的内部未在标准输出流读取器上设置编码引起的。我已经用自己的控制台应用程序复制了这种行为

这里讨论的方法是:

缺少的是在
ProcessStartInfo
上设置编码的方法,例如:

├── interpret@0.3.10
├── pretty-hrtime@0.2.2
├── deprecated@0.0.1
├── archy@1.0.0
├── minimist@1.1.0
├── tildify@1.0.0 (user-home@1.1.1)
├── semver@4.2.0
├── v8flags@1.0.8
├── chalk@0.5.1 (escape-string-regexp@1.0.2, ansi-styles@1.1.0, support
├── orchestrator@0.3.7 (stream-consume@0.1.0, sequencify@0.0.7, end-of-
├── liftoff@0.13.6 (extend@1.3.0, flagged-respawn@0.3.1, resolve@1.0.0,
├── vinyl-fs@0.3.13 (graceful-fs@3.0.5, mkdirp@0.5.0, vinyl@0.4.6, defa
└── gulp-util@3.0.2 (object-assign@2.0.0, array-differ@1.0.0, array-uni
gh2@0.6.3, multipipe@0.1.2, lodash.template@2.4.1, dateformat@1.0.11)
StandardErrorEncoding = Encoding.UTF8
我能看到的唯一解决方法(除了向Nant提交请求外)是编写一个自定义任务。就这么简单:

[TaskName("customexec")]
public class CustomExecTask : ExecTask
{
    protected override void PrepareProcess(Process process)
    {
        base.PrepareProcess(process);
        process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
        process.StartInfo.StandardErrorEncoding = Encoding.UTF8;
    }
}

但是,除了使用任务外,我一直在努力加载自定义任务。

如果使用
exec
任务上的
output
参数将输出直接传输到文件,会发生什么情况?谢谢@JamesThorpe,说得好。经过测试,它的性能也一样。很好的发现。如果没有打开一个新的bug,那么可能值得一看是否已经有一个bug为它打开了。开发人员响应并为最近出现的问题创建了修复程序。