如何从Visual Studio代码运行Windows Bash作为运行任务?
以下是我尝试tasks.json这样做的一些尝试.
{
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": [ "RunShellScript.bat" ],
"showOutput": "always"
}
Run Code Online (Sandbox Code Playgroud)
RunShellScript.bat只有这一行:bash myShellScript.sh.如果您只是从开始打开cmd,并键入该行,它将执行.如果您只是双击该文件,它也可以完美运行.但是,从VSCode启动时,此输出只会挂起,直到我终止它.
尝试2号:
{
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": [ "bash myShellScript.sh" ],
"showOutput": "always"
}
Run Code Online (Sandbox Code Playgroud)
这也像上面一样挂起.
尝试3号:
{
"version": "0.1.0",
"command": "C:/Windows/System32/bash",
"isShellCommand": false,
"args": [ "myShellScript.sh" ],
"showOutput": "always"
}
Run Code Online (Sandbox Code Playgroud)
这给了我:
Failed to launch external program C:/Windows/System32/bash myShellScript.sh
spawn C:/Windows/System32/bash ENOENT
Run Code Online (Sandbox Code Playgroud)
我也尝试过"isShellCommand"在某些情况下将变量设置为true和false,但无济于事.
有谁知道如何做到这一点?
使用C,我可以用通用文本编辑器(ig nano)编写程序,并在Lunix终端中编译
gcc mySum.c -o mySum
Run Code Online (Sandbox Code Playgroud)
获取一个窗口询问输入并返回输出.
#include <stdio.h>
int main(){
int x;
int y;
int sum;
printf("Program that sums two numbers.\n\nPlease type the first one:\n");
scanf("%d", &x);
printf("Type the second one:\n");
scanf("%d", &y);
sum = x + y;
printf("The sum of %d and %d is %d\n", x, y, sum);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在没有Visual Studio/MonoDevelopment的情况下,我可以在F#中生成相同类型的程序吗?
我发现使用裸体文本编辑器非常有启发性,就像我在使用C一样.这使我更加专注于学习,而IDE的帮助较少.此外,文本编辑器(如nano或记事本++或其他)提供了比fsharpi编写程序更灵活的工具.通过这种方式,当程序完成时,我将它以与我在示例中使用C相同的方式将其提供给编译器.
我会说通过实现这个功能
let mySum x y =
x + y
Run Code Online (Sandbox Code Playgroud)
同
fsharpc mySum.fs
Run Code Online (Sandbox Code Playgroud)
但我没有得到如何实现它.我找到了这个参考,但它有点先进.
我想.sh在 C++ 项目中使用适用于 Linux 的 Windows 子系统运行 Bash shell 脚本 ( ) 作为 Visual Studio 中构建事件的一部分。
但是当我这样做时有很多错误,我似乎无法找到引号、撇号和反斜杠的正确组合来首先运行 Bash,或者正确地将路径传递给脚本。
如何让 Visual Studio 将我的 Bash shell 脚本作为构建事件运行?
我在Visual Studio 2017中设置了一些生成后命令,这些命令应允许我运行System32(wsl.exe)当前拥有的程序。但是,Visual Studio没有看到该程序。
我试图设置命令以dir C:\Windows\System32\查看它可以列出的所有文件,实际上,它没有列出我所拥有的约4600个文件中的1000个文件,包括wsl.exe我要尝试的文件跑。在命令提示符下运行同一命令时,文件数正确显示。
我试图以whoamipost-build命令运行,它返回的用户与我在命令提示符下运行相同命令的用户相同。
我想念什么吗?
windows batch-file post-build-event visual-studio post-build
bash ×2
windows ×2
windows-subsystem-for-linux ×2
batch-file ×1
c ×1
f# ×1
linux ×1
post-build ×1