Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a cmd using "system()" doesn't look for path

Tags:

c++

cmd

system

I'm trying to execute a graphviz/dot cmd from within my program,
but I'm still getting the error sh: dot: command not found.

So that's the line that matters:

system("dot -Tpng myfile.txt -o mypic.png");

Executing it on the terminal works pretty well, cause dot is set into my path variable. Trying to execute the same programmatically ends up in the described error.

Is there any trick using the system cmd where I have to mention my path additionally?
(Btw: I already did include stdlib.h, dunno wether that's important...)

Thx a lot!

like image 900
Thkru Avatar asked Nov 27 '25 14:11

Thkru


1 Answers

You can try something like this:

#include <stdlib.h>

int main()
{
    system("PATH=$PATH:<YOUR PATH TO **dot**>;<**dot** and the rest>");
}

as shocking as it seems, this works for me ... (obviously replace between < > ... )

like image 135
Ferenc Deak Avatar answered Nov 30 '25 04:11

Ferenc Deak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!