【问题标题】:Command Prompt result from PowershellPowershell 的命令提示符结果
【发布时间】:2013-12-30 17:10:11
【问题描述】:

我有一个生成的文本文件,需要使用从命令提示符运行的程序进行验证。我正在尝试构建一个 powershell 脚本,它将运行命令并告诉我文本文件是否成功(没有错误)。当命令运行时,它只在屏幕上显示如下输出。

There were 0 warning, 0 fatal, and 0 system errors.

Please press Enter key to quit the program.

我目前正在使用下面的命令来给我这个输出。

Start-Process "C:\Program Files (x86)\file\file.exe" "C:\abc.txt" -NoNewWindow

我需要读取屏幕上的输出并通过字符串匹配确定结果是否成功(真/假)

非常感谢任何帮助/想法

【问题讨论】:

    标签: powershell command prompt


    【解决方案1】:

    使用Select-String:

    $pattern = 'There were 0 warning, 0 fatal, and 0 system errors.'
    
    ... | Select-String $pattern -SimpleMatch -Quiet
    

    【讨论】:

    • 嗨,abc.txt 是正在读取的文件。结果的输出只打印在powershell屏幕上
    • @user2861854 然后将输出通过管道传输到Select-String。查看修改后的答案。
    猜你喜欢
    • 2014-08-09
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 2011-05-22
    相关资源
    最近更新 更多