I'm writing a library where the C program provides an API to a client C program that includes it. As part of its functionality, the C library file popen's a Python script, running a Flask server, which the C program will write to, through a pipe. My problem is, by what path should I invoke the Python file?
My current solution is to write a makefile that places all the user's compiled binaries in a specific bin directory and I hardcode the path from that bin directory to the python file in the variable passed to popen. This is precarious and would cause the system to break if the user moves the binary around.
Directory structure:
.
├── README.md
├── bin
│ └── a.out
├── Makefile
├── src
│ ├── server
│ │ └── server_main.py
│ ├── mylib.c
│ └── mylib.h
└── tests
└── test_0.c
The current janky C code (in mylib.c):
pype = popen("python3 ../src/server/server_main.py", "w");
Client program can be anywhere, not just in tests directory.
I'm hoping for a way I can make this a less inflexible solution to the user, and not have a relative path in the C file.