1

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 ================
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • 1
    What a warm welcome to SO, thanks. Look, I've spent several hours researching this, and trying to figure this out. Getting nowhere I might add. Even after I posted this question, I'm still working on it. I have no intention of abusing the knowledge in this community. I greatly respect Stack Overflow, considering most problems I've had, have been already asked and I never needed to make an account. You're implication that I immediately gave up and came on here is rather insulting. – PastTheFuture Jan 26 '14 at 11:00
  • Don't worry, that's a perfectly good question, IMHO. SO is great in general, but there are always members who will frustrate you with their negative attitude. That's life :) – psxls Jan 26 '14 at 15:47

1 Answers1

3

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.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
  • Thank you, It works. I love you. Could you further explain what this does and why it must be done this way? – PastTheFuture Jan 27 '14 at 18:44
  • @PastTheFuture I am not sure it _must_ be done that way, there are probably several other ways. I just looked at the user documentation for NppExec, searched for "variables" and wrote up my findings. NppExec has a limited command language, a bit like the Windows batch language but not as powerful. I saw a two step method to provide your answer, first get the drive letter, second use in it a NppExec command. – AdrianHHH Jan 27 '14 at 21:46