开发者

Why is "<" input redirect not implemented in PowerShell?

开发者 https://www.devze.com 2023-03-21 11:59 出处:网络
Why is input redirection not implemented in PowerShell? To do something like this: mysql -u root < create.sql

Why is input redirection not implemented in PowerShell?

To do something like this:

mysql -u root < create.sql

I had to switch to "cmd.exe".

Is there an alternative way of doing this in PowerShell?

Please note that the output redirection ">" is implemented in PowerShell. Please consider this before giving an answe开发者_运维知识库r.


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.


I don't think MySQL will accept PowerShell objects piped to it - as Stephan says though, you could use Get-Content and pipe it to the next command.

Check out Stack Overflow question Is PowerShell ready to replace my Cygwin shell on Windows? for reasons on why they haven't copied Unix shells.

0

精彩评论

暂无评论...
验证码 换一张
取 消