Skip to content

Instantly share code, notes, and snippets.

@yohm
Created March 7, 2017 06:01
Show Gist options
  • Save yohm/3123a58b0f05fa9b84c05bbf71d47fc6 to your computer and use it in GitHub Desktop.
Save yohm/3123a58b0f05fa9b84c05bbf71d47fc6 to your computer and use it in GitHub Desktop.
wrapper_sample.py
import os, sys, json, subprocess
# Load JSON file
fp = open( '_input.json' )
params = json.load( fp )
# Prepare input file
f = open('configuration.xml', 'w')
param_txt = """<configuration>
<input>
<length value="%d" />
<velocity value="%f"/>
<time value="%d"/>
<seed value="%d"/>
</input>
</configuration>
""" % (params['length'], params['velocity'], params['time'], params['_seed'])
f.write(param_txt)
f.flush()
# Execution of the simulator
simulator = os.path.abspath(os.path.dirname(__file__)) + "/my_simulator.out"
cmd = [simulator, '-c', 'configuration.xml']
sys.stderr.write("Running: %s\n" % cmd)
subprocess.check_call(cmd)
sys.stderr.write("Successfully finished\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment