문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top