Search code examples
c++notepad++mingwnppexec

MinGw doesn't execute the program if file name has spaces


So I use notepad++'s NppExec to directly compile and execute C++ files.

npp_save
cd "$(CURRENT_DIRECTORY)"
g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
NPP_RUN $(NAME_PART)

This all works fine, now assuming I have this piece of code:

#include <iostream>
using namespace std;
    int main() {
        cout << "This is a normal statement" << endl;
        cout << "This statement uses endl;" << endl;
        cout << "This one has " << "multiple " << "chevrons" << "Cant tell huh?" << endl;
        cout << "This is a flush statement, this does not break line like this :" << flush;
        cout << "Me flush statement" << endl;
    system("pause");
    return 0;
    }

I use the above executing code to compile it.....

Well this will work if the filename doesn't have any spaces like

Filename.cpp
New.cpp
example.cpp
nospace.cpp

But if I use spaces...

Hello World.cpp
This has a space.cpp
New error.cpp

It creates the following error:

NPP_SAVE: D:\C++\My Projects\New text.cpp
CD: D:\C++\My Projects
Current directory: D:\C++\My Projects
g++ "New text.cpp" -o New text -march=native -O3
Process started (PID=13652) >>>
g++: error: text: No such file or directory
<<< Process finished (PID=13652). (Exit code 1)
NPP_RUN: New text
; executing: NPP_RUN New text
- the specified file was not found
================ READY ================

Before you say that its because I have wrong in my code, it doesn't, that's the same file I encountered the problem with, the code is copy pasted....I named the file Test File.cpp and got the error but after changing to TestFile.cpp it didn't show the above error, also the code wasn't edited

Why and how do I avoid that?


Solution

  • The obvious answer is to simply not use spaces in your file names. It's only asking for problems.

    But in this case have you tried using " around the NAME_PART variable?

    g++ "$(FILE_NAME)" -o "$(NAME_PART)" -march=native -O3
    NPP_RUN "$(NAME_PART)"