2

How do we get this command to run on Powershell with out error : The '<' operator is reserved for future use.

C:\Users\Me\my-git-repo > git am < MyFix.patch
    The '<' operator is reserved for future use.
    At line:1 char:9
    + git am < <<<<  MyFix.patch
    + CategoryInfo          : ParserError: (<:OperatorToken) [],..      
    + FullyQualifiedErrorId : RedirectionNotSupported
mklement0
  • 382,024
  • 64
  • 607
  • 775
ashishp
  • 23
  • 2

1 Answers1

3

Use either:

Get-Content MyFix.patch | git am

or:

cmd /c 'git am < MyFix.patch'

Both should work equally well. Windows Powershell simply doesn't support IO redirection with < for now, so you either need to pipe the text to stdin using | (Get-Content[1] sends the contents of MyFix.patch to stdout and | feeds it along to git am's stdin); alternatively, run the command through CMD.exe.


[1] Alternatively, use the built-in alias type.

mklement0
  • 382,024
  • 64
  • 607
  • 775
Derek Redfern
  • 1,009
  • 12
  • 18
  • 1
    @ashishp, for the future, please notice that PowerShell is roally screwed up with regard to character encoding when using stream redirection: it uses UTF-16 for this unless told otherwise. See [this](http://stackoverflow.com/q/1707397/720999) for one example. So if you need to work with Git *and* use stream redirection, consider using plain old `cmd.exe` or use one of [better alternative console implementations](http://superuser.com/q/268042/130459) or use Git bash (which is shipped with GfW). – kostix Jul 03 '14 at 09:57
  • 1
    @kostix: UTF-16 as the default in Windows PowerShell only applies to `>` / `>>`, i.e., _output redirection_, which does _not_ come into play in _pipelines_. There, it is the value of preference variable `$OutputEncoding` that determines how strings sent to _external programs_ are encoded. Unfortunately, however, the default is to use _ASCII_ encoding, which means that non-ASCII characters are lost (transliterated to literal `?` chars.) In short: `$OutputEncoding` is what you need to adjust if your output contains non-ASCII chars. – mklement0 Jan 28 '19 at 16:32
  • 2
    @kostix: P.S.: Note that the cross-platform [PowerShell _Core_](https://github.com/PowerShell/PowerShell) edition (available since early 2018) sensibly defaults to _BOM-less UTF-8_ in these scenarios. – mklement0 Jan 28 '19 at 16:33