Based on TIG’s and Aerilius’ replies I managed to find a solution.
Here’s my general system-call-with-no-flashing-window method.
require "tempfile"
# Run system call without flashing command line window on Windows.
# Runs asynchronously.
# Windows only hack.
#
# @param cmd String.
#
# @return [Void].
def self.system_call(cmd)
# HACK: Run the command through a VBS script to avoid flashing command line
# window.
file = Tempfile.new(["cmd", ".vbs"])
file.write("Set WshShell = CreateObject(\"WScript.Shell\")\n")
file.write("WshShell.Run \"#{cmd.gsub('"', '""')}\", 0\n")
file.close
UI.openURL("file://#{file.path}")
nil
end
As this code runs asynchronously I used this method, based on Aerilius’s ImageMagic library, to run a piece of code only once a file has been created.
# Run block once a file has been created.
#
# @param path [String]
# @param async [Boolean]
# @param delay [Flaot]
# @param block [Proc]
#
# @return [Void]
def self.on_exist(path, async = true, delay = 0.2, &block)
if File.exist?(path)
block.call
return
end
if async
UI.start_timer(delay) { on_exist(path, async, delay, &block) }
else
sleep(delay)
on_exist(path, async, delay, &block)
end
nil
end