Last active
December 10, 2015 23:28
-
-
Save henteko/4509631 to your computer and use it in GitHub Desktop.
同一ディレクトリ内の*.cppファイルが更新されるたびに、コンパイル実行するスクリプト 実行ファイル名と同一の.inファイルを用意すると、入力として扱ってくれます 準備 $ gem install fssm 実行 $ ruby run.rb 競技プログラミング用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fssm' | |
LINE = "--------------------------" | |
def run_system(base, file) | |
file_names = file.split(".") | |
input_file_name = file_names[0] + ".in" | |
puts "" | |
puts "RUN: #{file}" | |
puts LINE | |
if system("g++ #{file} -o #{file_names[0]}") | |
if File.exist?("#{input_file_name}") | |
IO.popen("./#{file_names[0]}", 'r+') do |io| | |
File.open("./#{input_file_name}", "r") do |f| | |
while line = f.gets do | |
io.puts line | |
end | |
end | |
io.close_write | |
while result = io.gets | |
puts result | |
end | |
end | |
puts LINE | |
puts "finished copying to the clipboard!" if system("cat #{file} | pbcopy") | |
else | |
system("./#{file_names[0]}") | |
end | |
end | |
end | |
FSSM.monitor('.', '*.cpp') do | |
update do|base, file| | |
run_system(base, file) | |
end | |
create do|base, file| | |
run_system(base, file) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment