【发布时间】:2013-01-10 04:00:14
【问题描述】:
我正在尝试在 java 中编译 typescript 文件。
这是一个有错误的“.ts”文件:
alert("hello, typescript");
errrrrrrrrrrrrrrrrrrrrrrrrrror
当我在 windows shell(cmd) 中编译时:
tsc hello.ts
它会报告错误消息:
E:/WORKSPACE/test/typescripts/hello.ts(2,0): The name 'errrrrrrrrrrrrrrrrrrrrrrrrror'
does not exist in the current scope
但是当我在 java 中这样做时:
String cmd = "cmd /C tsc hello.ts";
Process p = Runtime.getRuntime().exec(cmd);
String out = IOUtils.toString(p.getInputStream());
String error = IOUtils.toString(p.getErrorStream());
System.out.println("### out: " + out);
System.out.println("### err: " + error);
打印出来:
### out:
### err: E:/WORKSPACE/test/typescripts/hello.ts(2,0):
您可以看到没有捕获到详细错误。我的代码哪里出了问题?
更新
我只是确定MS提供的tsc.exe没有这个问题,我在这个问题中运行的是从npm安装的tsc.cmdnpm install typescript
【问题讨论】:
-
试试 apache common exec,我认为这应该可以帮助你。
-
恐怕是typescript的编译器
tsc的问题。由于我尝试了Java以外的一些工具(grunt.js),他们也只能得到第一行错误消息。 -
我只是确定MS提供的
tsc.exe没有这个问题,我在这个问题中运行的是从npm安装的tsc.cmdnpm install typescript -
如果有帮助,这是一个从 java 进行 typescript 编译的项目:github.com/martypitt/typescript4j