【记录】vscode 使用 WSL PHP

来自GitHub上的一个issue:Is it possible to use wsl bash php for php.validate.executablePath

Windows Host

d:\wsl-tools\php.bat

@echo OFF
setlocal ENABLEDELAYEDEXPANSION

rem Collect the arguments and replace:
rem  '\' with '/'
rem  'd:' with 'mnt/d'
rem  '"' with '\"'
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:D:=/mnt/d%
set v_params=%v_params%
set v_params=%v_params:"=\"%

rem Call the windows-php inside WSL.
rem windows-php is just a script which passes the arguments onto
rem the original php executable and converts its output from UNIX
rem syntax to Windows syntax.
C:\Windows\system32\bash.exe -l -c "windows-php %v_params%"

WSL

/usr/local/bin/windows-php

#!/bin/bash
# Pass all the arguments to PHP.
output=$(php "$@")
# Perform UNIX->WINDOWS syntax replacements.
output="${output//$'\n'/$'\r'$'\n'}"
output="${output//\/mnt\/d/D:}"
output="${output//\//\\}"
# Echo corrected output.
echo $output

tips:记得添加执行权限

VSCode in Windows Host

setting:

"php.validate.executablePath": "d:\\wsl-tools\\php.bat"

猜你喜欢

转载自www.cnblogs.com/alanabc/p/10727285.html
wsl