在cmd中模拟tee unix端口时出现问题
我试图在cmd中模拟unix端口在cmd中模拟tee unix端口时出现问题,unix,cmd,Unix,Cmd,我试图在cmd中模拟unix端口tee。我正在尝试: tasklist >con >log.txt 但它不起作用。它只是回显结果,而不是登录到文本文件中。请提供帮助。如果您使用的是受支持的Windows系统,它将具有PowerShell & tasklist | Tee-Object -FilePath .\tee.txt | Out-File -FilePath .\tee2.txt 这可以在cmd.exe shell中使用以下命令完成: powershell -NoL
tee
。我正在尝试:
tasklist >con >log.txt
但它不起作用。它只是回显结果,而不是登录到文本文件中。请提供帮助。如果您使用的是受支持的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
将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
Set Inp=WScript.Stdin
Set Outp=Wscript.Stdout
设置Fso=CreateObject(“Scripting.FileSystemObject”)
Set File=Fso.CreateTextFile(WScript.Arguments(0),True)
如果错误号为0,则
Outp.WriteLine“Error:&err.number&&err.description&&from”&err.source
清楚
wscript.exit
如果结束
直到Inp.AtEndOfStream
Line=Inp.readline
输出写入线
File.WriteLine行
环
使用
cscript //nologo tee.vbs "%userprofile%\Desktop\winini.txt" < "%windir%\win.ini"
cscript//nologo tee.vbs”%userprofile%\Desktop\winini.txt“<%windir%\win.ini”
我创建了一个工具,用于在批处理文件中模拟tee
:
@ECHO OFF
SETLOCAL
SET Append=false
IF /I "%~1]=="/a" ( SET Append=true & SHIFT )
IF "%~1"== "" GOTO help
IF "%~2"== "" GOTO help
SET Counter=0
FOR /F %%A IN ('DIR /A /B %1 2^>NUL') DO CALL :Count "%%~fA"
IF %Counter% GTR 1 ( SET Counter= & GOTO Syntax )
SET File=%1
DIR /AD %File% >NUL 2>NUL
IF NOT ERRORLEVEL 1 ( SET File= & GOTO Syntax )
SET Y=
VER | FIND "Windows NT" > NUL
IF ERRORLEVEL 1 SET Y=/Y
IF %Append%==false (COPY %Y% NUL %File% > NUL 2>&1)
FOR /F "tokens=1* delims=]" %%A IN ('FIND /N /V ""') DO (
> CON ECHO.%%B
>> %File% ECHO.%%B
)
ENDLOCAL
GOTO:EOF
:Count
SET /A Counter += 1
SET File=%1
GOTO:EOF
:help
ECHO.
ECHO Display text on screen and redirect it to a file simultaneously ECHO Usage: some_command ^| TEE.BAT [ /a ] filename
ECHO.
ECHO Where: "some_command" is the command whose output should be redirected
ECHO "filename" is the file the output should be redirected to
ECHO /a appends the output of the command to the file,
ECHO rather than overwriting the file
ECHO.
ECHO Made by Wasif Hasan.
用法:命令| tee[/a]文件名
。
/a
开关将输入附加到文件,而不是覆盖它
这在Unix中甚至不起作用。您将stdout重定向到con,然后再次将其重定向到log.txt。正如斯蒂芬所说,这可能是一个重复的问题。