Created
July 19, 2018 22:27
-
-
Save andyczerwonka/9a7048fafc9be38f8050c9ed8f11051e to your computer and use it in GitHub Desktop.
Errors with the submit process
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
import subprocess | |
def solve_it(input_data): | |
cmd = "java -jar ./anyint-scala/target/scala-2.12/anyint.jar " + input_data | |
p = subprocess.Popen( | |
cmd, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, | |
shell=True) | |
(out, err) = p.communicate() | |
if 0 == p.wait(): | |
return out | |
else: | |
return err | |
if __name__ == '__main__': | |
print('This script submits the integer: %s\n' % solve_it('123')) |
Here's my solver.py
(though it's from 2014):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
from subprocess import Popen, PIPE
def solve_it(input_data):
# Writes the inputData to a temporay file
tmp_file_name = 'tmp.data'
tmp_file = open(tmp_file_name, 'w')
tmp_file.write(input_data)
tmp_file.close()
# Runs the command: java Solver -file=tmp.data
process = Popen(['java', '-Xmx4g', '-cp', '../target/scala-2.10/optimiziation-assembly-1.0.jar',
'knapsack.Search', tmp_file_name], stdout=PIPE)
(stdout, stderr) = process.communicate()
# removes the temporay file
os.remove(tmp_file_name)
return stdout.strip()
import sys
if __name__ == '__main__':
if len(sys.argv) > 1:
file_location = sys.argv[1].strip()
input_data_file = open(file_location, 'r')
input_data = ''.join(input_data_file.readlines())
input_data_file.close()
print solve_it(input_data)
else:
print 'This test requires an input file. Please select one from the data directory. (i.e. python solver.py ./data/ks_4_0)'
@adamw I made the invalid assumption that the input data was supposed to be the input to my answer... it is not...
They use that input data as a general input for all the assignments, and in this case, it's moot. I'm supposed to ignore it, which is why they send an empty string in the example.
Thanks for sharing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using sbt-assembly fat jars, and just calling a subprocess. While I don't see any errors when I run this locally, there is an issue with
submit.py
submission process. Now, if I replace line #5 withIt works just fine. Which is very strange, given it’s just concatenation. How did you interface to Scala?