如何在PowerShell中訪問cmd的con偽檔案

powershell發表於2008-07-04

文章出處: http://tfl09.blogspot.com/2005/10/monad-and-command-console.html

                  http://mow001.blogspot.com/2005/10/sample-of-mine-used-at-reskitnet.html

cmd使用者可能喜歡使用copy con ...這個命令, con是一個偽檔案, 表示接受使用者的輸入, 並將其儲存到檔案中.

下面是 Thomas Lee 寫的一個小指令碼, 指令碼歷史很悠久了...那時候PowerShell還叫MSH呢.

# CopyfromConsole.msh
# Author Thomas Lee, based on a news posting by an unknown user
# This function copies text from the console and pipes it to a filee
# which gets around MSH's lack of a CON: (or abilty to do copy con: <file>!)
# if you call this without any paramaters, out-file prompts for a filename
 
 
FunctionCopyfromConsole {
param ($outfile="")
 
if ($outfile-eq"")
 {
    [system.console]::in.readtoend() | out-file
 }
Else
 {
    [system.console]::in.readtoend() | out-file$outfile
 }
}
 
set-aliascopyconCopyfromConsole

相關文章