Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 返回win32ole模块打开的CMD隐藏实例的exitcode?_Ruby_Win32ole - Fatal编程技术网

Ruby 返回win32ole模块打开的CMD隐藏实例的exitcode?

Ruby 返回win32ole模块打开的CMD隐藏实例的exitcode?,ruby,win32ole,Ruby,Win32ole,我知道如何在windows中打开CMD实例并获取返回代码 puts %x[Tasklist /v | Find "%tmp:~0,30%" >NUL] response = $?.exitstatus 这很有效 但是现在我需要打开CMD的一个隐藏实例,我只知道如何使用Win32ole模块,函数exitstatus向我发送了一个错误。 我不知道为什么 请帮助获取该实例的退出代码,或者以其他方式 打开并获取隐藏实例的exitcode require 'win32ole' shell = WI

我知道如何在windows中打开CMD实例并获取返回代码

puts %x[Tasklist /v | Find "%tmp:~0,30%" >NUL]
response = $?.exitstatus
这很有效

但是现在我需要打开CMD的一个隐藏实例,我只知道如何使用Win32ole模块,函数exitstatus向我发送了一个错误。 我不知道为什么

请帮助获取该实例的退出代码,或者以其他方式 打开并获取隐藏实例的exitcode

require 'win32ole'
shell = WIN32OLE.new('Shell.Application')

shell.ShellExecute('CMD', '/K Tasklist /v | Find "%tmp:~0,30%" >NUL',
'', '', 0)
response = $?.exitstatus
    if response == 0
        puts "hola"
        end
nil:NilClass的未定义方法“exitstatus” 命名者

谢谢你

我尝试了另一种更有效的方法来解决此问题:

require 'win32/api'
include Win32

# Callback example - Enumerate windows
EnumWindows     = API.new('EnumWindows', 'KP', 'L', 'user32')
GetWindowText   = API.new('GetWindowText', 'LPI', 'I', 'user32')
EnumWindowsProc = API::Callback.new('LP', 'I'){ |handle, param|
  buf = "\0" * 200
  GetWindowText.call(handle, buf, 200);

  if (!buf.index(param).nil?)
    puts "window was found: handle #{handle}"
    0 # stop looking after we find it
  else
    1
  end
}
EnumWindows.callEnumWindowsProc,“此处标题”


拜拜

CMD的隐藏实例是什么意思?您没有定义response,可能是想使用response=shell.ShellExecute。。。。