Search code examples
javanode.jsherokunode-pty

/app/.jdk/bin/java: cannot execute binary file using node-pty on Heroku


I am trying to create a node-pty process. When developing locally, this works fine and there is no problem. However, when this runs on Heroku, it gives the error: /app/.jdk/bin/java: cannot execute binary file

I tried running it with just ["java"], and that gives the same error. So, its unable to start the java binary.

However, when I manually type the command, it works just fine.

  const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';

  const ptyProcess = pty.spawn(shell, ["java", "-jar", "Klox.jar"], {
    name: 'xterm-color',
    cols: 80,
    rows: 30,
    cwd: process.env.HOME,
    env: process.env
  });

Any idea how I can solve this?


Solution

  • Solved the problem,

    Instead of spawning the shell with powershell or bash, spawn the shell directly with the executable that you're trying to run. So, java in my case.

    Effectively, what I did:

      const ptyProcess = pty.spawn("java", ["-jar", "Klox.jar"], {
        name: 'xterm-color',
        cols: 80,
        rows: 30,
        cwd: process.env.HOME,
        env: process.env
      });
    

    So, "java" instead of old shell variable.

    One another thing to keep in mind, on windows add .exe extension to the end, otherwise it will say file not found. For eg: java.exe on windows and java on linux.