Reputation: 29
So, i wrote a code, that would compile a C++ code using tdm gcc compiler. My code uses openfiledialog
to allow the user to choose the file to be compiled and then I construct a String command as,
cmd = "/c g++ " + openfiledialog.filename.toString() + " -o temp.exe";
And then i'm executing this command in a normal way using process instance. But, if there are spaces in filepath, eg: "D:\haha haha\test.cpp" then the g++ compiler shows an error saying no such directory haha etc etc. how to overcome this?
Upvotes: 0
Views: 759
Reputation: 58244
You'll need quotes around the file name to form the g++
command line:
cmd = "/c g++ \"" + openfiledialog.filename.toString() + "\" -o temp.exe";
Alternatively, you could post-process the value returned by .toString()
to insert an escape (backslash \
) character before each space. But the quote method is easier.
Upvotes: 1