Python Forum

Full Version: Help with subprocess..call
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Came out of the old BASIC. Using Linux Mint 18.2 fully updated. The old os.system command now
no longer. Below is my code. For information have done "chmod +x verify-expenses.py".
Need explicit help with executing menu choices.
tia
oldcity

#!/usr/bin/python
import subprocess
ans=True
while ans:
    print ("""
    1.Add Expenses
    2.Print/View Expenses
    3.Verify Entries
    4.Exit/Quit
    """)
    ans=raw_input("What would you like to do? ") 
    if ans=="1": 
      print("\n Add Expenses")
      subprocess.call("Add-Expenses.py") 
    elif ans=="2":
      print("\n Print/View Expenses")
      subprocess.call("Expense-Rpt.py")
    elif ans=="3":
      print("\n Verify Entries")
      subprocess.call("Verify-Expenses.py") 
    elif ans=="4":
      print("\n Goodbye")
      break 
    elif ans !="":
      print("\n Not Valid Choice Try again") 
$ python Basic-Menu.py

    1.Add Expenses
    2.Print/View Expenses
    3.Verify Entries
    4.Exit/Quit
    
What would you like to do? 3

 Verify Entries
Traceback (most recent call last):
  File "Basic-Menu.py", line 20, in <module>
    subprocess.call("Verify-Expenses.py") 
  File "/usr/lib/python2.7/subprocess.py", line 523, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
subprocess.call opens a sub-shell - and in a (sub)shell you have to provide a path to your executable (if it - the executable -is not in Linux PATH variable).

E.g., "./Verify-Expenses.py"

PS Consider switching to Python3