3

I'm trying to reconstruct how to execute a bash shell .sh file on my Windows machine from within Notepad++ using NPPExec. (I've done this successfully before, but my HDD crashed and I don't recall how I did it previously.)

When it was working before, I would run the NPPExec script that called a .sh file, and it showed me the console output of the .sh file processing in Notepad++ as if it were processing in cygwin.

This is the example .sh file that I'm trying to get to work:

message="Testing"
echo $message

This file is located in the root of C:.

Failed Attempts:

None of the following three methods work:

  • Execute: C:\nppexec.sh

Response:

CreateProcess() failed with error code 193:
%1 is not a valid Win32 application.
  • Execute: npp_exec C:\nppexec.sh

Response:

message="Testing"
CreateProcess() failed with error code 2:
The system cannot find the file specified.    
$message
  • Adding #! /bin/bash to the .sh file as the first line just causes an additional error when npp_exec is run:

    NPP_EXEC: C:\nppexec.sh
    #! /bin/bash
    CreateProcess() failed with error code 2:
    The system cannot find the file specified.
    
Assad Ebrahim
  • 6,234
  • 8
  • 42
  • 68
Validatorian
  • 73
  • 1
  • 2
  • 8

4 Answers4

3

The solution was to call bash directly:

C:\cygwin\bin\bash --login -c "command.sh"
Spudley
  • 166,037
  • 39
  • 233
  • 307
Validatorian
  • 73
  • 1
  • 2
  • 8
3

I have the same error while trying to execute a batch file on windows.

I resolved the problem by executing at first command cmd in console of notepad++, then E:\test.bat

I also have a mksnt installed on my window pc.

by starting at first the bash in console of notepad++, the test shell work well now

bash
C:\nppexec.sh
petitchamp
  • 55
  • 7
1

Use this Run command

C:\cygwin64\bin\bash.exe -l -c "cd \"$0\" ; echo $@; \"./$1\"; exec bash;" "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"

You can save this command for later use from Run dialog box.

For git bash, change the path like this:

C:\Progra~1\Git\bin\bash -l -c "cd \"$0\" ; echo $@; \"./$1\"; exec bash;" "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"

phhu
  • 1,462
  • 13
  • 33
lalthomas
  • 442
  • 5
  • 14
1

With a single keystroke I wanted to execute the shell script of the active Tab using Cygwin within notepad.

After few hours looking online and experimenting, I finally came up with

  1. install NppExec plugin
  2. Hit F6
  3. paste the following code:

    //save the file NPP_SAVE //redirect console output to $(OUTPUT) & silent mode npe_console v+ -- //convert winpath to cygpath D:\cygwin64\bin\bash -lc "cygpath \"$(FULL_CURRENT_PATH)\" //execute the file D:\cygwin64\bin\bash -lc "$(OUTPUT)"

Hope that save some time to some people