Recently, I started to get involved in the Ruby programming language (as it is in RPG Maker VX Ace version 1.9.2) and there are a lot of questions. Can I run / execute an external program or open the drive. I got interested because of the indie horror of games on Game Maker (I know that GM has a different programming language).

I would be glad if somehow help you.

If it is not difficult to write a sample code, or a link to the explanation of a similar topic.

    3 answers 3

    Yes, you can run the external program in reverse quotes. Most likely you will have to work with the drive through some external program (I'm afraid of platform-specific).

    `/path/to/external_program` 
    • I tried to use these quotes. It gave me this: Invalid escape character syntax L:\Games\MLFP (New)\game.exe - ZEkA10000
    • @ ZEkA10000 In Windows, you will have to escape the slash \, thank you, Windows developers for a reasonable choice of a separator in the paths to the files - 30 years soon this problem. - cheops

    Ways to launch "other programs" are listed in the answer to another question: Is there an analogue of the Subprocess module in Ruby and Java as in Python?

    About CD-ROM, I see the 2007 solution on Win32OLE: http://rubyonwindows.blogspot.ru/2007/05/automating-windows-shell-with-ruby.html - in principle, it should work on modern Ruby and Win7.
    But there is a way through the MS PsExec proxy: https://community.spiceworks.com/topic/34382-how-to-open-a-cd-drive-door-remotely

    Among all the ways this seems to me the most convenient, if briefly:

     IO.popen(command) 

    And for myself, I wrote this function:

     require 'colored' # запуск внешней команды с сохранением вывода # если в выводе попадется true_pattern, то возращаем его индекс def sysrun(command, true_patterns, debug) # запустить и считать вывод $lines = IO.popen(command + " 2>&1").readlines.join.split("\n") # если включен режим дебага, то вывести все на экран if debug puts # декоративный отступ puts "\t" + "command: ".bold.black + command.to_s.green puts "\t" + "true patterns: ".bold.black + true_patterns.to_s.yellow $lines.each { |line| puts "\t" + line.to_s.cyan } end # в случае если есть пустой паттерн соответствия, но также пустой вывод - возвращаем тру true_patterns.each { |pattern| return 0 if (pattern.empty? && $lines.empty?) } true_patterns.delete("") # удаляем пустые паттерны, чтобы следующая проверка не заглючила # пройтись по строкам и паттернам $lines.each do |line| true_patterns.each_with_index { |pattern, indx| return indx if (line.match pattern) } end return false end 

    Call:

     sysrun("dir", ["Volume"], true)