7

如何从Visual Studio代码运行Windows Bash作为运行任务?Windows Bash和Visual Studio代码:如何将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"变量真假在一些案件,但无济于事。

有谁知道如何做到这一点?

回答

6

我也一直在寻找看看我可以做同样的事情。

andlrc - 我已经试过了你的两个选项,他们都没有做到这一点。这个问题似乎是在庆典在任何情况下适当的Visual Studio代码运行在它无法识别我已经试过各种方法:

  • “命令”:“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代码的默认构建操作(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,不幸的是, t似乎理解这一点,并且构建任务不运行。

+8

一个不太冒险的解决方案是尝试运行'C:\ Windows \ sysnative \ bash.exe'。 –

+0

你能编辑你的文章以包含你使用过的tasks.json或launch.json吗? – atzero

+0

我所谓的'解决方案',无论出于何种原因,都停止了工作......调查。 –

0

尝试:

{ 
    "version": "0.1.0", 
    "command": "bash", 
    "isShellCommand": true, 
    "args": [ "myShellScript.sh" ], 
    "showOutput": "always" 
} 

或者你可以一个认领添加到您的文件:

#!/bin/bash 

然后写脚本路径:

{ 
    "version": "0.1.0", 
    "command": "/path/to/script.sh", 
    "isShellCommand": true, 
    "args": [], 
    "showOutput": "always" 
} 
+0

我的剧本确实有家当往上顶,但我会尝试这两种 – atzero

+0

更新:对不起队友,他们都didnt工作=/ – atzero

2

对具有新安装bash我的Windows 10的机器,这正常工作对我来说:

{ 
    "version": "0.1.0", 
    "command": "bash", 
    "isShellCommand": true, 
    "args": [ "shellscript.sh" ], 
    "showOutput": "always" 
} 

的家当版本shellscript.sh作为command并不为我工作。

您还可以使用bash -c "<command>"来运行任意命令:

{ 
    "version": "0.1.0", 
    "command": "bash", 
    "isShellCommand": true, 
    "args": ["-c", "echo \"test\""], 
    "showOutput": "always" 
} 

enter image description here

+0

32或64位?和你的shellscript.sh中有什么?我在微软就这个问题提出了一个问题,他们能够复制我曾经遇到过的相同问题 - [链接](https://github.com/Microsoft/vscode/issues/6579) –

+0

64位,让我们把讨论移到github上。 –

相关问题