Python Forum
How to launch a program through python script - Mac OS Mojave
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to launch a program through python script - Mac OS Mojave
#1
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:
Error:
$ python bandom_voronota_paleisti.py > 3dvo.pdb1 sh: input_file: No such file or directory
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 puzzled

The 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_file
Shouldn'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
Reply
#2
"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.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error on first Python launch garryp4 5 570 May-07-2024, 03:56 PM
Last Post: deanhystad
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,582 Jun-29-2023, 11:57 AM
Last Post: gologica
  Launch Python IDLE Shell from terminal Pavel_47 5 1,390 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Launch Windows Application OEMS1 0 2,227 Mar-26-2021, 07:42 PM
Last Post: OEMS1
Photo Python won`t launch error newbieee 0 1,832 Feb-02-2021, 11:51 PM
Last Post: newbieee
  How to kill a bash script running as root from a python script? jc_lafleur 4 6,103 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  Launch another python command without waiting for a return. SpongeB0B 13 11,348 Jun-18-2020, 10:45 AM
Last Post: Yoriz
  win32 API: Launch Application to RDP session from background process python script rangeshgupta 0 2,228 May-28-2020, 09:41 PM
Last Post: rangeshgupta
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,394 May-28-2020, 05:27 PM
Last Post: micseydel
  Why my program works from script but not from GUI? Matgaret 0 1,580 Dec-13-2019, 01:51 PM
Last Post: Matgaret

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020