Skip to content

Instantly share code, notes, and snippets.

@ilmoeuro
Last active March 26, 2018 11:24
Show Gist options
  • Save ilmoeuro/5c9904dd6a20b9b1b1b877d7086ef136 to your computer and use it in GitHub Desktop.
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.
@powershell -executionpolicy bypass -file "%~dp0ps-wsl-wrapper.ps1" %~n0 %*
$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