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

前端 未结 3 954
醉梦人生
醉梦人生 2020-12-16 03:00

how can I run the Windows Bash from Visual Studio code as a run task?

Here are some of my many attempts at tasks.json to do this.

{
           


        
相关标签:
3条回答
  • 2020-12-16 03:27

    Try:

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

    Or you can add a shebang to your file:

    #!/bin/bash
    

    and then write the path to the script:

    {
        "version": "0.1.0",
        "command": "/path/to/script.sh",
        "isShellCommand": true,
        "args": [],
        "showOutput": "always"
    }
    
    0 讨论(0)
  • I too was looking to see how I could do the same thing.

    andlrc - I've tried your two options and neither of them seem to do the trick. The issue seems to be in that bash is not recognised in whatever context Visual Studio Code runs it in. I've tried various approaches:

    • "command": "C:/Windows/System32/bash.exe"
    • "command": "bash"
    • "command": "bash.exe"

    I'll keep trying and post back if I get something working.

    Edit: Got it. Credit to this man - https://aigeec.com/using-windows-10-anniversary-bash-with-visual-studio-code/

    In summary, what it boils down to is that I am on a 64 bit operating system which means bash.exe is located in C:\Windows\System32. Once i'd copied bash.exe into SysWOW64 as the blog post suggests, the default build action (Ctrl+Shift+B) of Visual Studio Code runs as you'd expect it to.

    This seems a bit of a hacky workaround - it's probably worth raising with MSFT to see if there's something we can do about it.

    Edit: Here's my tasks.json as requested:

    {
      // 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 contains only one command; 'gulp' :-) but you could essentially put whatever you want in there, I suppose you could have several .sh scripts to cater for the different tapes of tasks

    In response to the use of Sysnative, unfortunately it doesn't seem to understand that and the build task does not run.

    0 讨论(0)
  • 2020-12-16 03:51

    On my Windows 10 machine that has a freshly installed bash, this works fine for me:

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

    The shebang version of shellscript.sh as command doesn't work for me.

    You can also use bash -c "<command>" to run an arbitrary command:

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

    0 讨论(0)
提交回复
热议问题