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上。 –

相關問題