Last active
March 26, 2018 11:24
-
-
Save ilmoeuro/5c9904dd6a20b9b1b1b877d7086ef136 to your computer and use it in GitHub Desktop.
WSL wrapper that translates file names and closes pipes, works with external tools like eclipse, Visual Studio etc... Put these files in the same folder. Doesn't work with programs that require input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@powershell -executionpolicy bypass -file "%~dp0ps-wsl-wrapper.ps1" %~n0 %* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$bashargs = New-Object System.Text.StringBuilder | |
foreach ($arg in $args) { | |
$arg = $arg -replace "^C:\\","/mnt/c/" | |
$arg = $arg -replace "\\", "/" | |
if ($arg.Contains(" ")) { | |
$arg = $arg -replace "`"", "\\`"" | |
} | |
if ($arg.Contains(" ")) { | |
[void]$bashargs.Append("`"") | |
} | |
[void]$bashargs.Append($arg) | |
if ($arg.Contains(" ")) { | |
[void]$bashargs.Append("`"") | |
} | |
[void]$bashargs.Append(" ") | |
} | |
$ps = New-Object System.Diagnostics.Process | |
$ps.StartInfo.Filename = "wsl.exe" | |
$ps.StartInfo.Arguments = $bashargs.ToString() | |
$ps.StartInfo.UseShellExecute = $False | |
$ps.StartInfo.CreateNoWindow = $True | |
$ps.StartInfo.RedirectStandardInput = $True | |
$ps.StartInfo.RedirectStandardOutput = $True | |
[void]$ps.Start() | |
$ps.StandardInput.Close() | |
write-output $ps.StandardOutput.ReadToEnd() | |
$ps.WaitForExit() | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment