0

I am building an application that needs access to a resource in the same folder (It needs the xsd file to validate the input file).

How can I reach this xsd file reliably?

To elaborate:

  1. I need to be able to call the executable:

    cd not/the/directory/of/the/program
    path/to/program -c config.xml
    
  2. What is the path to use here?

    subprocess.Popen("xmllint --noout --schema ?/?/config.xsd " + configfilename)
    
aiao
  • 4,621
  • 3
  • 25
  • 47
  • Possible duplicate of [How do I get the path of the current executed file in Python?](https://stackoverflow.com/questions/2632199/how-do-i-get-the-path-of-the-current-executed-file-in-python) – Roland Weber Jun 02 '19 at 12:11
  • You should be able to get the current working dir with `os.getcwd()`? – Oluwafemi Sule Jun 02 '19 at 12:15

1 Answers1

0

Take a look at the zeroth command-line argument your program gets. It's usually the name of the program, and might also include a path to the program. Combine that with the current directory. Then use realpath or some equivalent of it to get rid of symbolic links. However, I think there are still some corner cases where this approach might fail.

You didn't specify /the programming language/ or operating system you are using. If you're writing a bash script, see here: https://stackoverflow.com/a/246128/11451509

For Python, see How do I get the path of the current executed file in Python?

If the operating system is Linux, you could also go through the /proc pseudo filesystem, as explained here: https://stackoverflow.com/a/738024/11451509

Roland Weber
  • 3,395
  • 12
  • 26