运行 来自 Visual Studio 的 Post-Build 命令行的 Linux 子系统
Running the Linux Subsystem from Visual Studio's Post-Build Command Line
我正在尝试 运行 来自 Visual Studio 2015 的 Post-Build 命令行的 Windows 10 Linux 子系统。也就是说,我有一个命令,其输出将通过管道传输到 bash
,例如 xyz | bash
。 bash
应依次启动 Windows 10 Linux 子系统并执行命令。
这在 运行 从常规 CMD.exe
命令行或 .bat
文件中执行命令时非常有效。但是,当 运行从 Visual Studio 2015 Post-、Pre-Build- 或 Pre-Link-Event 命令行 直接 [=36] =],通过 call cmd /C
call 或外部 .bat
文件作为 proxy,失败并显示错误代码 255
并打印类似 "Command 'bash
' not found." 的内容。当尝试使用 bash.exe
的完整路径时,这也会失败。
如何从 Visual Studio 的命令行 运行 bash
?
旁注:我正尝试在 C/C++ 项目中 运行 这个。
我在 32 位 C++ 应用程序中使用 bash
时也遇到了这个问题。
问题是 bash
仅是 64 位的——当您尝试从 32 位应用程序使用它时,您对 C:\Windows\System32\bash.exe
的调用将被重定向到 C:\Windows\SysWOW64\bash.exe
不存在。
要绕过重定向,您必须在从 32 位应用程序调用 bash 时使用 C:\Windows\Sysnative\bash.exe
。我实际上制作了一个批处理 (.bat
) 代理,我将其添加到 PATH
中以使事情变得更容易。
bash.bat:
@echo off
if exist "C:\Windows\Sysnative\bash.exe" (
C:\Windows\Sysnative\bash.exe %*
) else (
C:\Windows\System32\bash.exe %*
)
我正在尝试 运行 来自 Visual Studio 2015 的 Post-Build 命令行的 Windows 10 Linux 子系统。也就是说,我有一个命令,其输出将通过管道传输到 bash
,例如 xyz | bash
。 bash
应依次启动 Windows 10 Linux 子系统并执行命令。
这在 运行 从常规 CMD.exe
命令行或 .bat
文件中执行命令时非常有效。但是,当 运行从 Visual Studio 2015 Post-、Pre-Build- 或 Pre-Link-Event 命令行 直接 [=36] =],通过 call cmd /C
call 或外部 .bat
文件作为 proxy,失败并显示错误代码 255
并打印类似 "Command 'bash
' not found." 的内容。当尝试使用 bash.exe
的完整路径时,这也会失败。
如何从 Visual Studio 的命令行 运行 bash
?
旁注:我正尝试在 C/C++ 项目中 运行 这个。
我在 32 位 C++ 应用程序中使用 bash
时也遇到了这个问题。
问题是 bash
仅是 64 位的——当您尝试从 32 位应用程序使用它时,您对 C:\Windows\System32\bash.exe
的调用将被重定向到 C:\Windows\SysWOW64\bash.exe
不存在。
要绕过重定向,您必须在从 32 位应用程序调用 bash 时使用 C:\Windows\Sysnative\bash.exe
。我实际上制作了一个批处理 (.bat
) 代理,我将其添加到 PATH
中以使事情变得更容易。
bash.bat:
@echo off
if exist "C:\Windows\Sysnative\bash.exe" (
C:\Windows\Sysnative\bash.exe %*
) else (
C:\Windows\System32\bash.exe %*
)