代码之家  ›  专栏  ›  技术社区  ›  Manuel Huber

在Ubuntu下用“sh”打开可执行文件

  •  0
  • Manuel Huber  · 技术社区  · 11 年前

    我正在使用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);
    
    1 回复  |  直到 11 年前
        1
  •  0
  •   Kyle Burton    11 年前

    在航站楼办理登机手续 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 命令

    推荐文章