gpt4 book ai didi

Windows Bash 和 Visual Studio Code : How can I launch bash as a run task?

转载 作者:可可西里 更新时间:2023-11-01 12:46:41 26 4
gpt4 key购买 nike

如何从 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"
}

这也挂起,就像上面一样。

第三次尝试:

{
"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,但无济于事。

有人知道怎么做吗?

最佳答案

我也想知道如何做同样的事情。

andlrc - 我已经尝试了您的两个选项,但它们似乎都无法解决问题。问题似乎在于 bash 在 Visual Studio Code 运行它的任何上下文中都无法识别。我尝试了各种方法:

  • “命令”:“C:/Windows/System32/bash.exe”
  • “命令”:“庆典”
  • “命令”:“bash.exe”

我会继续尝试,如果我有一些工作,我会回发。

编辑:知道了。感谢这个人 - https://aigeec.com/using-windows-10-anniversary-bash-with-visual-studio-code/

总而言之,归结为我使用的是 64 位操作系统,这意味着 bash.exe 位于 C:\Windows\System32 中。一旦我按照博客文章的建议将 bash.exe 复制到 SysWOW64 中,Visual Studio Code 的默认构建操作 (Ctrl+Shift+B) 就会按照您的预期运行。

这似乎是一个有点棘手的解决方法 - 可能值得向 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 Bash 和 Visual Studio Code : How can I launch bash as a run task?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37248106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com