【问题标题】:record command lines of cmd.exe记录cmd.exe的命令行
【发布时间】:2019-03-22 17:44:49
【问题描述】:

我需要记录一些在 Windows 上的 cmd.exe 程序中输入的命令行输入。我从 powershell 进程启动它,所以我尝试了这种方法,解释了here

PS (location)> cmd.exe | Tee-Object -file Cmd.exe.log

它越来越近了,但我需要得到这个......

  • 如何只记录输入的命令,而不记录输出?

  • 如何查看提示光标,如何保持键盘抛出的“箭头”特殊命令回忆之前的命令?

【问题讨论】:

    标签: powershell cmd command-line-interface


    【解决方案1】:

    Start-Trascript 记录了您输入的所有命令。更多官方文档:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-6

    示例跟踪的完整输出是

    **********************
    Windows PowerShell transcript start
    Start time: 20190322104506
    Username: DOMAIN\user
    RunAs User: DOMAIN\user
    Configuration Name: 
    Machine: MAICHINE_NAME (Microsoft Windows NT 10.0.17763.0)
    Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    Process ID: 31428
    PSVersion: 5.1.17763.316
    PSEdition: Desktop
    PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.316
    BuildVersion: 10.0.17763.316
    CLRVersion: 4.0.30319.42000
    WSManStackVersion: 3.0
    PSRemotingProtocolVersion: 2.3
    SerializationVersion: 1.1.0.1
    **********************
    Transcript started, output file is C:\transcripts\transcript0.txt
    
    C:\projects\> ls
    
    
        Directory: C:\projects\
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d-----       03/01/2019     16:07                X
    d-----       18/02/2019     16:56                Y
    d-----       21/03/2019     15:49                Z
    d-----       22/03/2018     16:17                T
    
    
    C:\projects\> cat .\paket.lock
    STORAGE: NONE
    
    C:\projects\> Stop-Transcript
    **********************
    Windows PowerShell transcript end
    End time: 20190322104539
    **********************
    
    

    【讨论】:

    • 感谢 Piotr Stapp 但需要预期的日志:1) 不是 powershell 命令列表,而是 cmd.exe 命令列表; 2) 输出结果不是预期的。
    • @FrançoisGardien 过滤输入和输出很容易(只是 grep),但据我所知 cmd 没有这样的日志记录。为什么不能在 powershell 中调用命令?
    • 我没想到会使用一些 powershell 命令,但我尝试了一下:它与我的 javascript 框架一起工作!此外,我在此文档语法中找不到如何仅过滤输入命令,您有什么建议?
    • 使用powershell而不是cmd来启动一些框架是可以的,但是我在文档中没有找到如何使用grep来获取输入?你能举个例子吗?
    • 谢谢,它就像一个魅力,我只改变了目的地:PS(位置)>。\dayLogs.log | Select-String "^C\:" > inputsOfDay.log
    猜你喜欢
    • 2012-10-13
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多