简体   繁体   中英

Executing and External Powershell Command from Ruby

I am trying to execute a Powershell command from ruby to capture the results and do some other processing.

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

Since the $_ variable is shared between the PS and Ruby i do get the following:

INFO: Could not find files for the given pattern(s).

Any ideas on how to accomplish this task.

$_.Message是Ruby全局变量吗?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM