2016-09-24 30 views

回答

1

這可能與一個老學校批處理文件。

php.bat

@echo off 
c:\windows\sysnative\bash.exe -c "php %*"` 

setting.json

"php.validate.executablePath": "c:\\PATH_TO\\php.bat" 
+0

嗯,我測試了它,但我無法讓它工作。 – palci12

+0

對於php.bat,將「sysnative」替換爲「system32」,並從字符串的末尾刪除'。 –

1

對方回答沒有爲我工作也不:經過一番工作,我想出了這兩個腳本:

這一個叫php.bat,我把它放在C:\wsl-tools\

@echo OFF 
setlocal ENABLEDELAYEDEXPANSION 
rem Collect the arguments and replace: 
rem '\' with '/' 
rem 'c:' with 'mnt/c' 
rem '"' with '\"' 
set v_params=%* 
set v_params=%v_params:\=/% 
set v_params=%v_params:C:=/mnt/c% 
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\sysnative\bash.exe -l -c "windows-php %v_params%" 

這一個叫做windows-php,放在WSL路徑的某處(我選擇了/usr/local/bin)。

# Pass all the arguments to PHP. 
output=$(php "[email protected]") 
# Perform UNIX->WINDOWS syntax replacements. 
output="${output//$'\n'/$'\r'$'\n'}" 
output="${output//\/mnt\/c/C:}" 
output="${output//\//\\}" 
# Echo corrected output. 
echo $output 

設置"php.validate.executablePath": "c:\\wsl-tools\\php.bat"適合我。

注意

您可能要遵循this issuethis pull request因爲它看起來像這個問題是要在未來的版本中的一個正式解決。

+0

對於x64版本的Visual Studio代碼,您必須將第一個腳本的最後一行更改爲: C:\ Windows \ system32 \ bash.exe -l -c「windows-php%v_params%」 – hdomos