Open In App

Python | os.get_exec_path() method

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system. os.get_exec_path() method in Python is used to get the list of directories that will be searched for a named executable while launching a process.
Syntax: os.get_exec_path(env = None) Parameter: env (optional): A dictionary representing the environment variables. The default value of this parameter is None. If its value is None environ is used. Return Type: This method returns a list which represents the paths of directories that will be used to search a named executable while launching a process.
Code #1: Use of os.get_exec_path() method Python3
# Python program to explain os.get_exec_path() method 
  
# importing os module 
import os

# Get the list of directories 
# that will be used to search 
# a named executable
# while launching a process
exec_path = os.get_exec_path()

# Print the list
print("Following paths will be searched for a named executable:")
print(exec_path)
Output:
Following paths will be searched for a named executable:
['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/usr/games', '/usr/local/games', '/snap/bin', '/usr/local/java/jdk-10.0.1/bin', '/usr/local/java/jdk-10.0.1/jre/bin', '/opt/jdk-10.0.1/bin', '/opt/jdk-10.0.1/jre/bin']
Code #2: Specifying env parameter Python3
# Python program to explain os.get_exec_path() method 
  
# importing os module 
import os

# Dictionary of environment variable
env = {'HOME': '/home/ihritik'}


# Get the list of directories 
# that will be used to search 
# a named executable
# while launching a process
exec_path = os.get_exec_path(env)

# Print the list
print("Following paths will be searched for a named executable:")
print(exec_path)
Output:
Following paths will be searched for a named executable:
['', '/bin', '/usr/bin']

Next Article
Article Tags :
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy