July 31, 2016 at 8:07 pm #3979
I have been working on using output from ST-Sim on a linux box (Ubuntu 14.04) to produce a 3D visualization, and I have come across something peculiar. I hope it is either something I am doing wrong, a knowledge gap, or is a bug.
Using the sample 3.0 ST-Sim library from the Getting Started tutorial, I was running the following commands (with some helper text) from a Django view to produce a model run and a subsequent report:
Model run command: sudo mono /home/taylor/sagebrush/3D-Landscape-Simulator/static/deps/st_sim/syncrosim-linux-1-0-24-x64/SyncroSim.Console.exe --run --lib=/home/taylor/sagebrush/3D-Landscape-Simulator/static/st_sim/libraries/ST-Sim-Sample-V3-0-24-take2.ssim --sid=10 Result scenario ID is: 259
Here is the bug – using python, I pack the string result of an
os.system(model_run_command)as a string, which returns the following id:
Resulting scenario id: 768
This ends up corresponding to
256 + (768 / 256) = 259, and this conversion was necessary to get back to the actual scenario id and produce the following report:
Report command: sudo mono /home/taylor/sagebrush/3D-Landscape-Simulator/static/deps/st_sim/syncrosim-linux-1-0-24-x64/SyncroSim.Console.exe --console=stsim --create-report --name=stateclass-summary --lib=/home/taylor/sagebrush/3D-Landscape-Simulator/static/st_sim/libraries/ST-Sim-Sample-V3-0-24-take2.ssim --file=/home/taylor/sagebrush/3D-Landscape-Simulator/static/st_sim/model_results/stateclass-summary-259.csv --sids=259
I admit that I am not the greatest linux person, but this seemed peculiar to me. Thoughts?
`August 1, 2016 at 11:58 am #3981alex.embreyParticipant
My understanding is that the return value for os.system is OS dependent. On Linux I believe the value is the return code combined with the signal used by the system to end the process. This probably accounts for what you are seeing. To avoid these types of issues, the Python docs recommend you use the subprocess library instead of os.system:
-AlexAugust 1, 2016 at 2:13 pm #3982
Thanks for the links, that does make more sense to use subprocess.
When I use subprocess like this:
import subprocess32 as sub_proc ... st_model_output_sid = str(sub_proc.call(st_exe + " " + st_run_model_command, shell=True))
It returns a scenario id 256 less than the id corresponding to the results id. I.e. If the scenario id is 296, the above returns 40. So that answers the divide by 256, but not the subtraction of 256…
TaylorAugust 1, 2016 at 4:23 pm #3983
Since the return code isn’t what I was looking for (it turns out), I am parsing the output of the model run and collecting the string that is passed back instead, grabbing the string as is and just using that value. Silly me!
Thank you for the help.
- You must be logged in to reply to this topic.