2014-01-20 13 views
2

我目前正試圖使用​​Patch.exe從PowerShell和P0參數調用Patch.exe

我能夠調用使用「&」命令的exe通過PowerShell來修補一些文件,但它不似乎正在讀我的p0輸入。我不是PowerShell的專家,任何幫助將不勝感激!

這裏什麼我打電話PS:

$output = & "$scriptPath\patch.exe" -p0 -i $scriptPath\diff.txt 

我的錯誤讀:

can't find file to patch at input line 5 
Perhaps you used the wrong -p or --strip option? 
The text leading up to this was: 

,我可以留下了P0參數從命令行我的補丁文件效仿。

以下是一些備選我已經嘗試過:

#$output = & "$scriptPath\patch.exe" -p0 -i "$scriptPath\diff.txt" 

#CMD /c 「$scriptPath\patchFile.bat」 (where patchFile.bat has %~dp0patch.exe -p0 < %~dp0diff.txt, seems like powershell reads < as 0<, so there is an error there I think) 

#GET-CONTENT $scriptPath\diff.txt | &"$scriptPath\patch.exe" "-p0" 

#GET-CONTENT $scriptPath\diff.txt | CMD /c 「$scriptPath\patch.exe -p0」 

謝謝!

回答

0

Patch.exe在錯誤的情況下開始,我解決了這個用推位置/彈出位置

這裏是我的代碼看起來像現在

Push-Location $scriptPath 
$output = & "$scriptPath\patch.exe" -p0 -i "$scriptPath\diff.txt" 
Pop-Location 

Keith在他的一個評論中還提到你可以使用:

[Environment]::CurrentDirectory = $pwd 

我沒有測試過這個,但我認爲它做了同樣的事情(Keith是一個PowerShell MVP,我只是一個學生)。

0

嘗試:

$output = & "$scriptPath\patch.exe" -p0 -i "$scriptPath\diff.txt" 
+0

之前嘗試過這一點,它給了我同樣的錯誤:( –

+0

@RichardLee這Patch.exe是這樣的嗎?它表明它在輸入行5的事實是否意味着它正在讀取您的diff.txt文件?如果那麼,那個文件中第5行的文件名是怎麼指定的呢? –

+0

我從gnuwin得到了patch.exe - 它是linux patch命令的windows版本。是的,我認爲它正確地讀取了我的diff.txt文件。只是表示差異變化的位置是'@@ -23,7 +23,7 @@' - 但是在其他一些錯誤中,它指向指示要更改哪個文件的行,如「--- CacheLib/config.xml \t(revision XXXXX)「 –