Thursday, 31 August 2017

Input redirection with powershell

PowerShell doesn't support input redirection, so it's impossible to do sql file import in usual way without invoking legacy CMD:
PS> mysql dbname < file.sql
At line:1 char:7
+ mysql < .\file.sql
+       ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : RedirectionNotSupported

Luckily it is possible to redirect input by taking file contents, which is, probably, more natural way to do:
PS> Get-Content .\file.sql | mysql dbname