【问题标题】:Running a bash shell script on Windows from within in Notepad++ using NppExec (and Cygwin)使用 NppExec(和 Cygwin)在 Notepad++ 中在 Windows 上运行 bash shell 脚本
【发布时间】:2012-06-27 20:23:36
【问题描述】:

我正在尝试使用 NPPExec 从 Notepad++ 中重构如何在我的 Windows 机器上执行 bash shell .sh 文件。 (我以前成功过,但是我的硬盘崩溃了,我不记得我以前是怎么做到的。)

当它之前工作时,我会运行调用 .sh 文件的 NPPExec 脚本,它会向我显示在 Notepad++ 中处理 .sh 文件的控制台输出,就像在 cygwin 中处理一样。

这是我试图开始工作的示例 .sh 文件:

message="Testing"
echo $message

此文件位于 C: 的根目录下。

尝试失败:

以下三种方法均无效:

  • 执行:C:\nppexec.sh

回复:

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

回复:

message="Testing"
CreateProcess() failed with error code 2:
The system cannot find the file specified.    
$message
  • 在 .sh 文件中添加 #! /bin/bash 作为第一行只会在运行 npp_exec 时导致额外的错误:

    NPP_EXEC: C:\nppexec.sh
    #! /bin/bash
    CreateProcess() failed with error code 2:
    The system cannot find the file specified.
    

【问题讨论】:

    标签: bash shell cygwin notepad++ nppexec


    【解决方案1】:

    解决办法是直接调用bash:

    C:\cygwin\bin\bash --login -c "command.sh"
    

    【讨论】:

      【解决方案2】:

      尝试在 Windows 上执行批处理文件时遇到同样的错误。

      我通过在notepad++的控制台中执行第一个命令cmd,然后E:\test.bat解决了这个问题

      我的 Windows 电脑上也安装了一个 mksnt。

      首先在notepad++的控制台中启动bash,现在测试shell运行良好

      bash
      C:\nppexec.sh
      

      【讨论】:

        【解决方案3】:

        通过单次击键,我想在记事本中使用 Cygwin 执行 活动选项卡的 shell 脚本。

        在网上找了几个小时和试验后,我终于想出了

        1. 安装 NppExec 插件
        2. 按 F6
        3. 粘贴以下代码:

          //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)"

        希望能为某些人节省一些时间

        【讨论】:

          【解决方案4】:

          使用此运行命令

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

          您可以在运行对话框中保存此命令供以后使用。

          对于 git bash,更改路径如下:

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

          【讨论】:

            最近更新 更多