在cmd中模拟tee unix端口的问题

问题描述 投票:1回答:2

我正在尝试在cmd中模拟unix端口tee。我正在尝试:

tasklist >con >log.txt

但是它不起作用。它只是回显结果,而不是登录到文本文件。请帮助。

unix cmd
2个回答
0
投票

如果您使用的是受支持的Windows系统,它将安装PowerShell。

& tasklist | Tee-Object -FilePath .\tee.txt | Out-File -FilePath .\tee2.txt

这可以在cmd.exe shell中使用:

powershell -NoLogo -NoProfile -Command "& tasklist | Tee-Object -FilePath .\tee.txt | Out-File -FilePath .\tee2.txt"

这将产生tee.txt和tee2.txt作为Unicode编码的文件。如果要将它们作为ASCII文件,则需要对其进行转换。

Get-Content -Path .\tee.txt | OutFile -FilePath .\tee3.txt -Encoding ascii
Get-Content -Path .\tee2.txt | OutFile -FilePath .\tee4.txt -Encoding ascii

0
投票

将Stdin写入文件和StdOut

放入名为tee.vbs的文件中>

Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Set Fso = CreateObject("Scripting.FileSystemObject")
Set File = Fso.CreateTextFile(WScript.Arguments(0), True)
If err.number <> 0 then
    Outp.WriteLine "Error: " & err.number & " " & err.description & " from " & err.source
    err.clear
    wscript.exit
End If
Do Until Inp.AtEndOfStream
    Line=Inp.readline
    outp.writeline Line
    File.WriteLine Line
Loop

使用

cscript //nologo tee.vbs "%userprofile%\Desktop\winini.txt" < "%windir%\win.ini"
© www.soinside.com 2019 - 2024. All rights reserved.