The '<' operator is reserved for future use
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 Pow开发者_StackOverflowerShell?
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
Also try:
cmd /c '.\test_cfdp.exe < test.full | tee test.log'
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
If you want to run this command more times, you can just make a *.bat file with the original syntax. That's another solution.
In case PowerShell is not mandatory , running the command in Command Prompt works fine.
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)
精彩评论