Windows Bash 和 Visual Studio 代码:如何将 bash 作为 运行 任务启动?
Windows Bash and Visual Studio Code: How can I launch bash as a run task?
如何将 Visual Studio 中的 运行 Windows Bash 编码为 运行 任务?
以下是我在 tasks.json
进行的多次尝试中的一些尝试。
{
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": [ "RunShellScript.bat" ],
"showOutput": "always"
}
RunShellScript.bat 只有这一行:bash myShellScript.sh
。如果您只是从头开始打开 cmd,然后键入该行,它将执行。如果您也双击该文件,它也 运行 完美。然而,当从 VSCode 启动时,此输出只是挂起,直到我终止它。
尝试次数 2:
{
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": [ "bash myShellScript.sh" ],
"showOutput": "always"
}
这也挂了,就像上面一样。
尝试次数 3:
{
"version": "0.1.0",
"command": "C:/Windows/System32/bash",
"isShellCommand": false,
"args": [ "myShellScript.sh" ],
"showOutput": "always"
}
这给了我:
Failed to launch external program C:/Windows/System32/bash myShellScript.sh
spawn C:/Windows/System32/bash ENOENT
我也尝试过在某些情况下将 "isShellCommand"
变量设置为 true 和 false,但无济于事。
有人知道怎么做吗?
尝试:
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": [ "myShellScript.sh" ],
"showOutput": "always"
}
或者您可以将 shebang 添加到您的文件中:
#!/bin/bash
然后写入脚本的路径:
{
"version": "0.1.0",
"command": "/path/to/script.sh",
"isShellCommand": true,
"args": [],
"showOutput": "always"
}
我也想看看如何做同样的事情。
andlrc - 我已经尝试了你的两个选项,但它们似乎都无法解决问题。问题似乎在于 bash 在任何上下文中都无法识别 Visual Studio 代码 运行。我尝试了各种方法:
- "command": "C:/Windows/System32/bash.exe"
- "command": "bash"
- "command": "bash.exe"
我会继续努力 post 如果我有一些工作,我会回来。
编辑:知道了。感谢这个人 - https://aigeec.com/using-windows-10-anniversary-bash-with-visual-studio-code/
总而言之,归结为我使用的是 64 位操作系统,这意味着 bash.exe 位于 C:\Windows\System32。一旦我按照博客 post 的建议将 bash.exe 复制到 SysWOW64 中,Visual Studio 的默认构建操作 (Ctrl+Shift+B) 代码 运行s 就像你期待它。
这似乎是一个有点棘手的解决方法 - 可能值得向 MSFT 提出建议,看看我们是否可以做些什么。
编辑:这是我的 tasks.json 请求:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": [ "./gulp.sh" ],
"showOutput": "always",
"tasks": [{
"taskName": "scripts",
"isBuildCommand": true,
"problemMatcher": "$gulp-tsc",
"isWatching": true
}]
}
gulp.sh只包含一个命令; 'gulp' :-) 但你基本上可以放任何你想要的东西,我想你可以有几个 .sh 脚本来满足不同的任务磁带
响应 Sysnative 的使用,不幸的是它似乎不理解并且构建任务不运行。
在我的 Windows 10 机器上新安装了 bash
,这对我来说很好用:
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": [ "shellscript.sh" ],
"showOutput": "always"
}
shellscript.sh 的 shebang 版本 command
不适合我。
你也可以使用bash -c "<command>"
到运行任意命令:
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": ["-c", "echo \"test\""],
"showOutput": "always"
}
如何将 Visual Studio 中的 运行 Windows Bash 编码为 运行 任务?
以下是我在 tasks.json
进行的多次尝试中的一些尝试。
{
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": [ "RunShellScript.bat" ],
"showOutput": "always"
}
RunShellScript.bat 只有这一行:bash myShellScript.sh
。如果您只是从头开始打开 cmd,然后键入该行,它将执行。如果您也双击该文件,它也 运行 完美。然而,当从 VSCode 启动时,此输出只是挂起,直到我终止它。
尝试次数 2:
{
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": [ "bash myShellScript.sh" ],
"showOutput": "always"
}
这也挂了,就像上面一样。
尝试次数 3:
{
"version": "0.1.0",
"command": "C:/Windows/System32/bash",
"isShellCommand": false,
"args": [ "myShellScript.sh" ],
"showOutput": "always"
}
这给了我:
Failed to launch external program C:/Windows/System32/bash myShellScript.sh
spawn C:/Windows/System32/bash ENOENT
我也尝试过在某些情况下将 "isShellCommand"
变量设置为 true 和 false,但无济于事。
有人知道怎么做吗?
尝试:
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": [ "myShellScript.sh" ],
"showOutput": "always"
}
或者您可以将 shebang 添加到您的文件中:
#!/bin/bash
然后写入脚本的路径:
{
"version": "0.1.0",
"command": "/path/to/script.sh",
"isShellCommand": true,
"args": [],
"showOutput": "always"
}
我也想看看如何做同样的事情。
andlrc - 我已经尝试了你的两个选项,但它们似乎都无法解决问题。问题似乎在于 bash 在任何上下文中都无法识别 Visual Studio 代码 运行。我尝试了各种方法:
- "command": "C:/Windows/System32/bash.exe"
- "command": "bash"
- "command": "bash.exe"
我会继续努力 post 如果我有一些工作,我会回来。
编辑:知道了。感谢这个人 - https://aigeec.com/using-windows-10-anniversary-bash-with-visual-studio-code/
总而言之,归结为我使用的是 64 位操作系统,这意味着 bash.exe 位于 C:\Windows\System32。一旦我按照博客 post 的建议将 bash.exe 复制到 SysWOW64 中,Visual Studio 的默认构建操作 (Ctrl+Shift+B) 代码 运行s 就像你期待它。
这似乎是一个有点棘手的解决方法 - 可能值得向 MSFT 提出建议,看看我们是否可以做些什么。
编辑:这是我的 tasks.json 请求:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": [ "./gulp.sh" ],
"showOutput": "always",
"tasks": [{
"taskName": "scripts",
"isBuildCommand": true,
"problemMatcher": "$gulp-tsc",
"isWatching": true
}]
}
gulp.sh只包含一个命令; 'gulp' :-) 但你基本上可以放任何你想要的东西,我想你可以有几个 .sh 脚本来满足不同的任务磁带
响应 Sysnative 的使用,不幸的是它似乎不理解并且构建任务不运行。
在我的 Windows 10 机器上新安装了 bash
,这对我来说很好用:
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": [ "shellscript.sh" ],
"showOutput": "always"
}
shellscript.sh 的 shebang 版本 command
不适合我。
你也可以使用bash -c "<command>"
到运行任意命令:
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": ["-c", "echo \"test\""],
"showOutput": "always"
}