
Error “The ‘<‘ operator is reserved for future use.” (SOLVED)
October 25, 2022
Analog “<” for PowerShell
On Linux, you can use the following construct:
COMMAND1 < FILE1
In this case, COMMAND1 will be executed with FILE1 as the input source instead of the keyboard, which is the normal standard input source.
The “<” operator corresponds to the use of “|” to be passed to standard input. For example, the following commands are identical:
COMMAND1 < FILE1 cat FILE1 | COMMAND1
Trying to use this construct in PowerShell throws an error.
For example command
mysql -uroot < C:\Users\MiAl\Downloads\all-databases.sql
ends with the following message:
ParserError: Line | 1 | mysql -uroot < C:\Users\MiAl\Downloads\all-databases.sql | ~ | The '<' operator is reserved for future use.
Similar error in PowerShell 5:
string:1 character:14 + mysql -uroot < C:\Users\MiAl\Downloads\all-databases.sql + ~ The '<' operator is reserved for future use. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : RedirectionNotSupported
Instead of syntax
COMMAND1 < FILE1
you need to use the following structure:
Get-Content FILE1 | COMMAND1
The Get-Content cmdlet will read the contents of FILE1. Symbol “|” (pipe, conveyor) means to pass the content to COMMAND1.
Thus, instead of
mysql -uroot < C:\Users\MiAl\Downloads\all-databases.sql
you need to use the following command:
Get-Content C:\Users\MiAl\Downloads\all-databases.sql | .\mysql -uroot
“./program < input.txt > output.txt” alternative for PowerShell
Consider the construction
./program < input.txt > output.txt
It means that the contents of the input.txt file are passed to the standard input of the “program” command, and the result of program execution is redirected to the output.txt file. But the above command will not work.
An analogue of the considered construction, which will work in PowerShell, is the following command:
Get-Content INPUT.txt | ./program > output.txt
Or you can use the PowerShell style variant:
Get-Content INPUT.txt | ./program | Out-File output.txt
Related articles:
- Output encoding issues in PowerShell and third-party utilities running in PowerShell (SOLVED) (100%)
- mysqldump in PowerShell corrupts non-Latin characters when exporting database (SOLVED) (80.1%)
- ImageMagick error on Windows: “magick: unable to open image ''test': No such file or directory @ error/blob.c/OpenBlob/3565. magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741.” (SOLVED) (53.6%)
- How to display all environment variables at the Windows command prompt (53.1%)
- How to manage services on Windows (53.1%)
- How to change the country in the Play Store (RANDOM - 50%)