How to launch a program through python script - Mac OS Mojave - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to launch a program through python script - Mac OS Mojave (/thread-18120.html) |
How to launch a program through python script - Mac OS Mojave - Aurimas - May-06-2019 Dear Python forum members, I am trying to write and launch a python script through terminal at Mac OS Mojave, however I am getting this error: The 3dvo.pdb1 file is in the exact location where I run the program from but it cannot be loaded through os.system, so I am puzzledThe code I have is this: import sys, os input_file_v2 = raw_input('> ') input_file_v1 = open(input_file_v2, 'r+') input_file = input_file_v1.read() os.system("voronota get-balls-from-atoms-file --annotated < input_file") # doesn't work with input_fileShouldn't it be possible to run my external program (voronota) that is run through terminal simply with raw_input? I have tried it but received the same error when not setting the input file to be readable. However, after setting it I still get this error. What could be the problem? Thank you very much fo your assistance. Sincerely, Aurimas RE: How to launch a program through python script - Mac OS Mojave - micseydel - May-07-2019 "input_file" is embedded as a string, it's not used as a variable. You need to do string formatting like so: "voronota get-balls-from-atoms-file --annotated < {}".format(input_file)Note that code like this is subject to security issues if anyone can specify the filename. Not likely an issue but hard to not at least bring up here. RE: How to launch a program through python script - Mac OS Mojave - kritesh - May-11-2019 If you’re not familiar with the language, you can recognize scripts written in Python by their distinctive “.py” file extension. Python scripts can be executed in a couple different ways, depending on what tools you have at your disposal. Hope above information will help you. |