The '<' operator is reserved for future use
Asked Answered
P

6

110

I am using PowerShell and am trying to run the following command:

.\test_cfdp.exe < test.full | tee test.log

test.full is a script that mimics command line inputs to test_cfdp.exe. However, I get the following error:

The '<' operator is reserved for future use.

Is there another way (i.e. cmdlet) I can use to get this command to work in PowerShell?

Phonolite answered 27/1, 2010 at 16:55 Comment(1)
Try to run this on normal command prompt and not on power shell.Poe
G
104

This was not supported in PowerShell v1 [and as of v5, it's still not...]

An example workaround is:

Get-Content test.full | .\test_cfdp.exe | tee test.log
Gymnasiast answered 27/1, 2010 at 17:4 Comment(3)
You can use the alias cat to get file content easier.Rivera
@aliayed Yes, or gc or type; however, it's common convention in forums etc to use the canonical cmdlet name explicitly, as anyone that knows the alias will cope, but the cmdlet name is far more searchable (if someone has a good link for an article that explains this, happy to edit it into this comment)Gymnasiast
What is the reason for this error anyways?Dropline
R
65

Also try:

cmd /c '.\test_cfdp.exe < test.full | tee test.log'
Ruffina answered 14/5, 2013 at 16:52 Comment(4)
tee is an alias for PowerShell's Tee-Object cmdlet, though, so this won't work the same/at all.Worse
this doesn't work at all, unless there's a real tee.exe or tee.bat... in %PATH%, because tee isn't available in cmd. It only works in PowerShell by default where tee is an aliasOpsonize
yes - running the command in Command Prompt works fine. This error is misleading.Parahydrogen
did the trick, thanksMood
R
8

In version 7 of PowerShell, you still need to use Get-Content to get the contents of an item in the specified location. For example, if you want to load a file into a Python script and write the result to a file. Use this construct:

PS > Get-Content input.txt | python .\skript.py > output.txt

Or with displayed and saved in a file:

PS > Get-Content input.txt | python .\skript.py | tee output.txt

Or switch to cmd to use the '<' operator:

C:\>python .\skript.py < input.txt > output.txt
Reggie answered 3/12, 2021 at 10:53 Comment(1)
Switching to cmd and using the < operator was the easiest solution in my case, thanks!Glaikit
M
4

In case PowerShell is not mandatory , running the command in Command Prompt works fine.

Morita answered 29/6, 2022 at 11:21 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Alcorn
That has already been proposed in this earlier and much-upvoted answer.Worse
S
3

Because I dev on windows and deploy on linux I have created this powershell function. The solutions above where not appropriate because the binary file I had to restore. The knowledge of the bash-script is borrowed from: How to invoke bash, run commands inside the new shell, and then give control back to user?

$globalOS = "linux" #windows #linux

function ExecuteCommand($command) {
    if($command -like '*<*') {
        #Workaround for < in Powershell. That is reserved 'for future use'
        if ($globalOS -eq "windows") {
            & cmd.exe /c $command
        } else {
            $wrappercommand = "''" + $command + " ; bash''"
            & bash -c $wrappercommand
        }
    } else {
        Invoke-Expression $command
    }
}

$command = "docker exec -i mydockerdb pg_restore -U postgres -v -d mydatabase < download.dump"
ExecuteCommand($command)

Subprincipal answered 29/9, 2022 at 11:20 Comment(0)
I
1

If you want to run this command more times, you can just make a *.bat file with the original syntax. That's another solution.

Insipience answered 8/6, 2013 at 9:20 Comment(1)
Dont use powershell, you can use cmd prompt. In windows go to respective folder and type cmd in address bar to open the cmd prompt and there < signs can be used.Poe

© 2022 - 2024 — McMap. All rights reserved.