Splunk Dev

Reliable file path in script independent of OS

rantravee
Path Finder

Hi,

I' using a custom Python script to index data into Splunk. Within the script I refer some dependencies and conf files using code like this :

conf_file = os.environ['SPLUNK_HOME']+'/etc/apps/my_app/default/my_conf_file.conf'
APP_BIN_DIR = SPLUNK_HOME + "/etc/apps/my_app/bin/"

Since this script is going to run both on Windows and Linux I wonder what would be a reliable pattern to use when referring to the location of other dependecies/resources within the file system

Tags (2)
0 Karma
1 Solution

Ayn
Legend

You should use os.path.join. It automatically gets the valid OS separator (available independently in os.path.sep) and concatenates an array of string intelligently using it.

conf_file = os.path.join(os.environ['SPLUNK_HOME'],'etc','apps','my_app','default','my_conf_file.conf')

View solution in original post

Ayn
Legend

You should use os.path.join. It automatically gets the valid OS separator (available independently in os.path.sep) and concatenates an array of string intelligently using it.

conf_file = os.path.join(os.environ['SPLUNK_HOME'],'etc','apps','my_app','default','my_conf_file.conf')

rantravee
Path Finder

As a Python beginner I'm surprised every day of what it has to offer

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...