java - 在 Java 中执行 Linux nodejs 命令行

标签 java linux node.js bower

我正在使用 Apache Commons Exec在我的项目中运行 bower操作系统(Linux 和 Windows)中的命令,这在 Windows 中运行良好,但在 Linux 中找不到命令“bower”,感谢您的帮助。

    String command="bower --allow-root";
    CommandLine commandline = null;
    if (isWindows()) {
        commandline = new CommandLine("cmd");
        commandline.addArguments(new String[] { "/c", command }, false);
    }
    if (isUnix()) {
        commandline = new CommandLine("/bin/bash");
        commandline.addArguments(new String[] { "-c", command }, false);
    }
    ExecuteCommandResponse executeCommandResponse = new ExecuteCommandResponse();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DefaultExecutor exec = new DefaultExecutor();
    PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
    exec.setStreamHandler(streamHandler);
    exec.setWorkingDirectory(workingDirectory);
    try {
        exec.execute(commandline);
    } catch (Exception e) {

    }

最佳答案

bower 是 JavaScript 文件,因此 bash 无法运行它。正确代码

if (isUnix()) {
    commandline = new CommandLine("/usr/local/bin/node");
    commandline.addArguments(new String[] { "/usr/local/bin/bower","--allow-root"}, false);
}

关于java - 在 Java 中执行 Linux nodejs 命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29832594/

相关文章:

linux - ARM 如何在 IRQ 处理程序中切换到 svc 模式?

node.js - 如何让 heroku 与 sequelize.js + postgres 兼容?

node.js - 在 Atlas 上使用 ReplicaSet 的 Mongoose

python - 区分多个 Websocket

java - 如何从java中的字符串数组中删除特定值?

java - 到底 (args.length>0) 是什么意思?

java - Spring Boot - Web 应用程序上下文 Bean 范围

java - 根据java中的索引号将元素移动到数组的前面

c++ - linux makefile等效?重要的

linux - 为什么计划策略和参数的设置在我的程序 - pthread Linux 中失败?