【问题标题】:Executing and External Powershell Command from Ruby从 Ruby 执行和外部 Powershell 命令
【发布时间】:2012-03-21 13:09:10
【问题描述】:

我正在尝试从 ruby​​ 执行 Powershell 命令以捕获结果并进行一些其他处理。

var = `powershell Invoke-Command -computername myserver {Get-Eventlog application -newest 200 |      where {$_.Message -match "Found 0 files to refresh"}}`
puts var

由于 $_ 变量在 PS 和 Ruby 之间共享,我确实得到以下信息:

信息:找不到给定模式的文件。

关于如何完成此任务的任何想法。

【问题讨论】:

    标签: ruby powershell


    【解决方案1】:

    $_.Message 是 Ruby 全局变量?

    var = `powershell Invoke-Command -computername myserver {Get-Eventlog application -newest 200 |      where {#{$_.Message} -match "Found 0 files to refresh"}}`
    

    【讨论】:

    • 不,$_.Message 是 Powershell 变量,但 ruby​​ 认为是文件句柄:S
    猜你喜欢
    • 1970-01-01
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    相关资源
    最近更新 更多