Reputation: 20117
I'm fairly new to the Windows API, and I'm having a lot of trouble just getting the dot program (which creates a graph using graphviz) to run from my program.
The command that I want to run, which works in cmd is this:
dot -Kfdp -n -Tpng -o "D:\Programming\VS\Visual Studio 2013\Projects\Graphs\Graphs\Input\topsort.png" "D:\Programming\VS\Visual Studio 2013\Projects\Graphs\Graphs\Input\topsort.dot"
However I'm consistently getting the error 2, The system cannot find the file specified
Here's my (simplified) code. Note that the value of ca at the end of the processing is the correct string, so that's not the problem.
//From earlier in the file
//#include <Windows.h>
//std::string filepath = "D:\\Programming\\VS\\Visual Studio 2013\\Projects\\Graphs\\Graphs\\Input\\topsort";
//Create structs
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo;
//Create a string and copy to a char*
string procArg = "dot -Kfdp -n -Tpng -o \"" + filepath + ".png\" \"" + filepath + ".dot\"";
char* ca = new char[procArg.size() + 1];
int size = (procArg.size() + 1) * sizeof(*ca);
int count = procArg.length();
procArg._Copy_s(ca, size, count);
ca[procArg.size()] = '\0';
//At the end of this, size = 182, count = 181,
//and ca = dot -Kfdp -n -Tpng -o "D:\Programming\VS\Visual Studio 2013\Projects\Graphs\Graphs\Input\topsort.png" "D:\Programming\VS\Visual Studio 2013\Projects\Graphs\Graphs\Input\topsort.dot"
//Attempt to create process
CreateProcess(NULL,
ca,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&StartupInfo,
&ProcessInfo);
Thanks!
Upvotes: 0
Views: 500
Reputation: 10868
CreateProcess has a number of different choices. The one you have picked may not be the best. Choices are:
Upvotes: 1
Reputation: 31
Looks like system could not find the PATH for dot program. I suggest you try giving absolute path of the dot program as part of procArg. This can also be validate by executing CMD and then try to execute the same command there.
Upvotes: 3