Can not run "~/OctoPrint/venv/bin/octoprint serve" using exec on node js



I want to start octoprint using my node js tool

When I try to use exec to run the same command that will run octoprint using terminal
I face error

{ Error: Command failed: sudo ~/OctoPrint/venv/bin/octoprint serve
sudo: /root/OctoPrint/venv/bin/octoprint: command not found

The code that I use to run the octoprint

exec('sudo ~/OctoPrint/venv/bin/octoprint serve',function (err,stdout,stderr) {

Is there any other way to start octoprint from within node js tool


sudo? Bad choice. Do not run OctoPrint as user root.

Will also make your issue go away since ~ with sudo refers to the home directory of user root at /root, and you've probably have setup OctoPrint somewhere else.

But really. Do. Not. Use. sudo.


If this is on an OctoPi-based install, you could assume that OctoPrint can be completely controlled via the script that were already part of that image:

sudo service octoprint start
sudo service octoprint stop
sudo service octoprint restart

This might seem like I didn't hear foosel's advice but trust me, it's different from running OctoPrint directly as root. The underlying scripts themselves do it the right way.



With out sudo
But I only copy the code after I tried what ever I can think about

I tried with out sudo in begging and also I can not run it