Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with subprocess..call
#1
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
Reply
#2
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
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  continue if 'subprocess.call' failes tester_V 11 5,144 Aug-26-2021, 12:16 AM
Last Post: tester_V
  printing out the contents aftre subprocess.call() Rakshan 3 2,742 Jul-30-2021, 08:27 AM
Last Post: DeaD_EyE
  subprocess call cannot find the file specified RRR 6 16,541 Oct-15-2020, 11:29 AM
Last Post: RRR
  Why wont subprocess call work? steve_shambles 3 2,661 Apr-28-2020, 03:06 PM
Last Post: steve_shambles
  subprocess.call - Help ! sniper6 0 1,516 Nov-27-2019, 07:42 PM
Last Post: sniper6
  Mock call to subprocess.Popen failing with StopIteration tharpa 7 5,913 Nov-08-2019, 05:00 PM
Last Post: Gribouillis
  Echo call to VLC bash using subprocess.Popen on Linux LuukS001 17 9,673 Jan-07-2019, 03:58 AM
Last Post: LuukS001
  Why is subprocess.call command not working? zBernie 5 10,727 Nov-19-2018, 11:11 PM
Last Post: snippsat
  subprocess.call salmaankamil 1 2,697 Jul-27-2018, 06:50 PM
Last Post: woooee
  [inconsistent output] subprocess.call to run cmd commands to get Kerberos ticket Yelin 2 4,987 Jun-08-2018, 09:02 AM
Last Post: Yelin

Forum Jump:

User Panel Messages

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