Question

I wanted to be able to compile and run C and C++ code from Notepad++ on my flash drive (Using PortableApps.com). I got MinGW and put it on my flash drive, I adjusted This Guy's NppExec script to work with a flash drive and it would work flawlessly except I don't always know what drive letter my flash drive is going to get.

When I pass it %CD:~0,2% it takes it as a string instead of a command. So the command:

cd %CD:~0,2%\MinGW\bin\

is attempted exactly as written. It doesn't try to convert the %CD:~0,2% into the drive letter. So if someone could help me figure out a way to better get the drive letter that would be nice.

Also, the reason I'm not just adding MinGW\bin\ to the system variables is because my school's computer's have security software that would prevent me doing so. And I would still need the drive letter.

My assumption, as to the reasoning for my problem, is that NppExec doesn't know what to do with the % signs. So if someone knows a way around this...?

Here is the full code:

npp_save
cd %CD:~0,2%\MinGW\bin\
g++ "$(FULL_CURRENT_PATH)" -o $(NAME_PART) -march=native -O2
cmd /c move /Y $(NAME_PART).exe $(CURRENT_DIRECTORY)\$(NAME_PART).exe
NPP_RUN $(CURRENT_DIRECTORY)\$(NAME_PART).exe

The Output shows NppExec clearly disregarding my change directory command. Here is the output:

NPP_SAVE: G:\Documents\ColumbiaCollege\C++CmpSc27\Assigns\Assign02-PRSA\JesseM_Assign02_RPS_Game.c
CD: %CD:~0,2%\MinGW\bin\
Current directory: G:\Documents\ColumbiaCollege\C++CmpSc27\Assigns\Assign02-PRSA
g++ "G:\Documents\ColumbiaCollege\C++CmpSc27\Assigns\Assign02-PRSA\JesseM_Assign02_RPS_Game.c" -o JesseM_Assign02_RPS_Game -march=native -O2
CreateProcess() failed with error code 2:
The system cannot find the file specified.

cmd /c move /Y JesseM_Assign02_RPS_Game.exe G:\Documents\ColumbiaCollege\C++CmpSc27\Assigns\Assign02-PRSA\JesseM_Assign02_RPS_Game.exe
Process started >>>
The system cannot find the file specified.
<<< Process finished. (Exit code 1)
NPP_RUN: G:\Documents\ColumbiaCollege\C++CmpSc27\Assigns\Assign02-PRSA\JesseM_Assign02_RPS_Game.exe
- the specified file was not found
================ READY ================
Was it helpful?

Solution

You could try the batch set command to put the drive letter into an environment variable, then use that variable in the NppExec script. To set the environment variable try something like:

set TheDriveLetter=%CD:~0,2%

To use it in the script use:

cd $(SYS.TheDriveLetter)\MinGW\bin\

There is more information in the section on variables in the NppExec documentation.

Notepad++ may itself have some environment variables that provide the drive more easily. You could try here for a list of them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top