2012-07-12 36 views
20

Cú pháp cần thiết để chuyển hướng đầu vào/đầu ra tiêu chuẩn trên Windows PowerShell là gì?Chuyển hướng đầu vào chuẩn output trong Windows PowerShell

Trên Unix, chúng tôi sử dụng:

$./program <input.txt >output.txt 

Làm thế nào để thực hiện nhiệm vụ tương tự trong PowerShell?

+0

liên quan: http://stackoverflow.com/questions/16098366/can-i-send-some-text-to-the-stdin-of-an-active-process-under-windows – eckes

Trả lời

25

Bạn không thể móc trực tiếp tệp vào stdin, nhưng bạn vẫn có thể truy cập stdin.

Get-Content input.txt | ./program > output.txt 
+0

này lần đọc toàn bộ tệp 'input.txt' vào bộ nhớ. Hãy cẩn thận nếu 'input.txt' có thể lớn. –

6

Đối với chuyển hướng đầu ra bạn có thể sử dụng:

command > filename  Redirect command output to a file (overwrite) 

    command >> filename  APPEND into a file 

    command 2> filename  Redirect Errors 

chuyển hướng đầu vào làm việc theo một cách khác. Ví dụ, hãy xem Cmdlet này http://technet.microsoft.com/en-us/library/ee176843.aspx

Các vấn đề liên quan