Switchkick
Switchkick

Reputation: 2796

How do I open a file within notepad++ with C++?

I'm trying to get my c++ program to open an sql file in notepad++. I can get it to open with notepad like this:

system("notepad.exe script_foo.sql");

But that's undesirable as it's not formatted. When I try to substitute notepad.exe for notepad++.exe like this:

system("'C:\Program Files\Notepad++\notepad++.exe' script_foo.sql");

I get a invalid syntax error.

Any issues where I'm going wrong?

Upvotes: 0

Views: 2148

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283911

The WinNT shell uses double-quotes to include spaces in a file name. Single quotes are not recognized. So you need

"C:\Program Files\Notepad++\notepad++.exe" script_foo.sql

as your command.

To embed this in C++ source code, you'll need to escape backslashes (as Andre already mentioned) and also the double-quotes.

system("\"C:\\Program Files\\Notepad++\\notepad++.exe\" script_foo.sql");

Upvotes: 2

André Caron
André Caron

Reputation: 45294

In C++, the backslash character \ is an escape character in strings. You need to double the backslashes to achieve what you really want:

system("'C:\\Program Files\\Notepad++\\notepad++.exe' script_foo.sql");

Upvotes: 1

Related Questions