使用 NppExec(和 Cygwin)在 Notepad++ 中在 Windows 上运行 bash shell 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11234289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running a bash shell script on Windows from within in Notepad++ using NppExec (and Cygwin)
提问by Validatorian
I'm trying to reconstruct how to execute a bash shell .shfile 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.)
我正在尝试.sh使用 NPPExec 从 Notepad++ 中重建如何在我的 Windows 机器上执行 bash shell文件。(我以前成功地做到了这一点,但我的硬盘坏了,我不记得我以前是怎么做到的。)
When it was working before, I would run the NPPExec script that called a .shfile, and it showed me the console output of the .sh file processing in Notepad++ as if it were processing in cygwin.
当它之前工作时,我会运行调用.sh文件的 NPPExec 脚本,它向我展示了 Notepad++ 中 .sh 文件处理的控制台输出,就像它在 cygwin 中处理一样。
This is the example .sh file that I'm trying to get to work:
这是我试图开始工作的示例 .sh 文件:
message="Testing"
echo $message
This file is located in the root of C:.
该文件位于 C: 的根目录中。
Failed Attempts:
失败的尝试:
None of the following three methods work:
以下三种方法均无效:
- Execute:
C:\nppexec.sh
- 执行:
C:\nppexec.sh
Response:
回复:
CreateProcess() failed with error code 193:
%1 is not a valid Win32 application.
- Execute:
npp_exec C:\nppexec.sh
- 执行:
npp_exec C:\nppexec.sh
Response:
回复:
message="Testing"
CreateProcess() failed with error code 2:
The system cannot find the file specified.
$message
Adding
#! /bin/bashto 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.
添加
#! /bin/bash到 .sh 文件作为第一行只会在运行 npp_exec 时导致额外的错误:NPP_EXEC: C:\nppexec.sh #! /bin/bash CreateProcess() failed with error code 2: The system cannot find the file specified.
回答by Validatorian
The solution was to call bash directly:
解决办法是直接调用bash:
C:\cygwin\bin\bash --login -c "command.sh"
回答by petitchamp
I have the same error while trying to execute a batch file on windows.
尝试在 Windows 上执行批处理文件时遇到相同的错误。
I resolved the problem by executing at first command cmd in console of notepad++, then E:\test.bat
我通过在记事本 ++ 的控制台中执行第一个命令 cmd,然后执行 E:\test.bat 来解决问题
I also have a mksnt installed on my window pc.
我的 windows 电脑上也安装了 mksnt。
by starting at first the bash in console of notepad++, the test shell work well now
首先在记事本++的控制台中启动bash,测试shell现在运行良好
bash
C:\nppexec.sh
回答by lalthomas
Use this Run command
使用这个运行命令
C:\cygwin64\bin\bash.exe -l -c "cd \"$0\" ; echo $@; \"./$1\"; exec bash;" "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"
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.
您可以从“运行”对话框保存此命令以备后用。
回答by Vigilat Harpocrates
With a single keystrokeI wanted to execute the shell script of the active Tabusing Cygwin within notepad.
通过一次按键,我想在记事本中使用 Cygwin执行活动选项卡的 shell 脚本。
After few hours looking online and experimenting, I finally came up with
经过几个小时的在线查找和试验,我终于想出了
- install NppExec plugin
- Hit F6
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)"
- 安装 NppExec 插件
- 按 F6
粘贴以下代码:
//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
希望为某些人节省一些时间

