2

I got a .patch file which I have to apply onto some source code. Unluckily, I am running on Windows. So I installed the Windows' port of the patch program from http://gnuwin32.sourceforge.net/packages/patch.htm and broght up PowerShell. But I'm not getting done, it always ends up in error. (Aside from the fact that GnuWin32 doesn't install within the "path"...)

First try:

PS D:\eclipsews\fix17435> "C:\Program Files (x86)\GnuWin32\bin\patch.exe" < 17435.patch
Der Operator "<" wird noch nicht unterstützt.
Bei Zeile:1 Zeichen:50
+ "C:\Program Files (x86)\GnuWin32\bin\patch.exe" < <<<<  bug-1032189.patch
    + CategoryInfo          : ParserError: (<:OperatorToken) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupported

Yes, my Power Shell speaks perfectly German, so googleing the error messages doesn't lead to—probably available—solutions on the net. ☹

Reading here on StackOverflow, I tried to use the "cat" equivalent: "Get-Content", but this ends up in an error, too:

PS D:\eclipsews\fix17435> Get-Content .\17435.patch | "C:\Program Files (x86)\GnuWin32\bin\patch.exe"
Ausdrücke sind nur als erstes Element einer Pipeline zulässig.
Bei Zeile:1 Zeichen:82
+ Get-Content .\bug-1032189.patch | "C:\Program Files (x86)\GnuWin32\bin\patch.exe" <<<<
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

Btw, calling “Get-Content .\17435.patch” stand-alone works.

Third, I checked the manual of "patch" if it is possible to specify an input file as parameter, to get arround the annoying redirection problem: Yes, using the -i option. But this seems to be blocked, too:

PS D:\eclipsews\fix17435> "C:\Program Files (x86)\GnuWin32\bin\patch.exe" -i 17435.patch
Sie müssen auf der rechten Seite des Operators "-" einen Wertausdruck angeben.
Bei Zeile:1 Zeichen:50
+ "C:\Program Files (x86)\GnuWin32\bin\patch.exe" - <<<< i bug-1032189.patch
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

How is stdin redirection on powershell and passing parameters done properly? Is there some documentation anywhere?

Community
  • 1
  • 1
Matthias Ronge
  • 9,403
  • 7
  • 47
  • 63
  • I found some (annoying) work-around, but better than none: Create a new link, point it to patch.exe. Then edit the link and put the -i name-of-your-input-file.patch option in the "destination" text box behind …/patch.exe". Unluckily, setting the work directory doesn’t help patch to find the files, so you have to provide the names in a DOS-style window coming up now. You can paste here from clipboard by clicking on the top-left icon, choose ‘Edit’ → ‘Paste’—not handsome, but better than nothing. – Matthias Ronge Oct 12 '12 at 08:46

2 Answers2

3

If the exe has a path that contains spaces, where you have to quote it, then you need to invoke it like so:

& "C:\Program Files (x86)\GnuWin32\bin\patch.exe" -i 17435.patch

If PowerShell sees:

"C:\Program Files (x86)\GnuWin32\bin\patch.exe" -i 17435.patch

It thinks it is evaluating a string followed by some operator -i that it doesn't recognize.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
0

I had a similar problem with PowerShell redirection not working as expected. I managed to work around it by spawning cmd.exe and using it to implement native redirection. Starting with your first example:

"C:\Program Files (x86)\GnuWin32\bin\patch.exe" < 17435.patch

This approach would use instead:

cmd /c "C:\Program Files (x86)\GnuWin32\bin\patch.exe" '<17435.patch'

mklement0
  • 382,024
  • 64
  • 607
  • 775
Burt_Harris
  • 6,415
  • 2
  • 29
  • 64