我正在使用Sonar的API( http://javadocs.sonarsource.org/4.5/apidocs/org/sonar/api/utils/command/Command.html )对于执行命令的函数,它表示“命令将使用sh可执行文件执行。” 我想做的只是使用
tslint路径/to/my/code.ts
在终端中(因为这是有效的)。但是这个该死的方法删除了带有“sh”的行,所以看起来像这样
sh tslint路径/to/my/code.ts
并告诉我错误
sh:0:无法打开tslint
如何解决这个问题,即使命令以sh开头,也只执行“tslint”?
谢谢你的帮助
编辑:因为你们中的很多人都问生成这个命令的java代码是什么样子的(不是我的,它来自一个开源项目):
Command command = Command.create("tslint"); command.addArgument("--config " + configFile + " --format json " + file.trim());
最终编辑: 工作版本:
Command command = Command.create("node"); command.addArgument(pathToTsLint); command.addArgument("--format"); command.addArgument("json"); command.addArgument("--config"); command.addArgument(configFile); command.addArgument(file.trim()); command.setNewShell(false);
在航站楼办理登机手续 which tslint 文件的完整路径。 从终端,您可以使用
which tslint
/bin/sh -c "/path/to/tslint /path/to/my/code.ts"
使用Sonar API:
Command command = Comman.create('/full/path/name/to/tslint'); command.addArgument("--config " + configFile + " --format json " + file.trim());
你不需要 -c 中的参数 sh 命令,但必须使用 tslint 命令
-c
sh
tslint