Why is “<” input redirect not implemented in PowerShell?

后端 未结 2 1082
礼貌的吻别
礼貌的吻别 2020-12-03 07:01

Why is input redirection not implemented in PowerShell?

To do something like this:

mysql -u root < create.sql

I had to switch to

2条回答
  •  眼角桃花
    2020-12-03 07:05

    Although I'm not entirely sure that this question belongs on Stack Overflow, have you looked at the PS Cmdlet for Get-Content? Look how it's used in the examples on TechNet in Using the Get-Content Cmdlet.

    Example:

    Get-Content c:\scripts\test.txt | Foreach-Object {Get-Wmiobject -computername $_ win32_bios}
    

    Update: Above link to TechNet is broken, but mentioned in comment by Chad Miller Scripting Guy's post Working Around Legacy Redirection Issues with PowerShell gives three options: -use CMD /c, Echo, and Get-Content.

提交回复
热议问题