diff options
author | crupest <crupest@outlook.com> | 2021-12-18 19:39:43 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-12-18 19:39:43 +0800 |
commit | dfdb5012705bcb3e13c10b22c63a351b9b2a708c (patch) | |
tree | cf6438d36a8b320623f3712f38a7399b89be383f /lanqiao-selection-match/java-gen-out.rb | |
parent | eb52b9626f4a31f92765a9fa2d9dc23869b99784 (diff) | |
download | life-dfdb5012705bcb3e13c10b22c63a351b9b2a708c.tar.gz life-dfdb5012705bcb3e13c10b22c63a351b9b2a708c.tar.bz2 life-dfdb5012705bcb3e13c10b22c63a351b9b2a708c.zip |
...
Diffstat (limited to 'lanqiao-selection-match/java-gen-out.rb')
-rwxr-xr-x | lanqiao-selection-match/java-gen-out.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lanqiao-selection-match/java-gen-out.rb b/lanqiao-selection-match/java-gen-out.rb new file mode 100755 index 0000000..bedad2d --- /dev/null +++ b/lanqiao-selection-match/java-gen-out.rb @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby + +require 'timeout' + +def run(no, count) + Dir.glob("./codes/*#{no}.java").each do |f| + code = File.read(f) + code.sub!(/public\s+class\s+\S+/, 'public class Main') + + java_file = f.sub('codes', 'temp') + + File.write(java_file, code) + + count.times do |i| + in_file = "./generator/#{no}-#{i + 1}.in" + out_file = "#{f.sub('codes', 'out').sub('.java', '')}-#{i + 1}.out" + pid = Process.spawn "/usr/local/opt/openjdk/bin/java #{java_file} < #{in_file} > #{out_file}" + Timeout.timeout(5) do + Process.wait pid + end + rescue Timeout::Error + puts "Timeout for #{f} when tests #{i + 1} case" + File.delete out_file + Process.kill 'KILL', pid + end + rescue StandardError + puts "Error for #{f}" + end +end + +run 'A', 3 +run 'B', 3 +run 'C', 4 |