How to run Heroku executable with node, works locally

This is my first SE question. Usually I can find the answer to something quite easily through this wonderful site, but, unfortunately, about this I can not find anything in what I am looking for, here or elsewhere. Let me explain the problem:

I wrote a C ++ program to do numerical calculations. It takes command line arguments and writes to stdout and works fine on my OSX system.

I want to host this online site for my peers to try it more easily, so I wrote some Node.js and Express code to get the input from the form and provide this as a command line argument for the executable. Then I execute the binary called a "factorizer" as follows:

const exec = require('child_process').exec; app.post('/', function (req, res) { var input = req.body.numberinput; //Number entered on the webpage const child = exec('./numericcomp ' + input, {timeout: 20000}, function(error, stdout, stderr) { //Code here writes stdout to the page } } 

The above works fine on my local machine, but when I deploy it to Heroku and then try entering (here I tried 2131), I get an error:

 Error: Command failed: ./numericcomp 2131 ./numericcomp: 3: ./numericcomp: Syntax error: word unexpected (expecting ")") 

which is assigned to the callback in exec.

So, I really don’t know what to do, the problem is that Heroku just does not start the executable correctly. I'm not particularly aware of how Heroku works, I read information about buildpacks, etc., but it seems like a very complicated process just to execute binary code. Is it because I have only one speaker and it cannot start the child process?

I would really appreciate it if someone could point me in the right direction here, it seems that I have done all the hard work, but I can not overcome the last obstacle.

+5
source share
1 answer

Well, I have this for work, it may be of interest to many, so I will post how I did it.

The problem was that the Heroku architecture is not the same as on my machine, and therefore, the compiled program simply will not work on Heroku. To get around this, I created a makefile to compile the source code in C ++ and clicked on Heroku using

 $ git push heroku master 

Then

 $ heroku run bash 

which essentially installs a bash shell with access to your Heroku instance.

Now compile the executable using

 $ make 

Then scp this executable file back to your local computer, and then

 $ git add . $ git commit -m "added working executable" 

and

 $ git push heroku master 

Then the working executable will be present in the Heroku application and will work exactly the same as on the local host.

+9
source

All Articles