The boost::process::search_path function seems to be unable to find files on some systems.
For example, for the following:
boost::process::search_path("example.exe");
On some systems, this function will always return an empty string (indicating that it could not find that file), regardless of whether or not file.txt exists within the directory or PATH variable. Is this an issue with permissions? And if so, how would I fix this?
Edit: Changed example to executable file.
Note: This answer did’t solve the author’s problem. See comments below.
The documentation for
boost::process::search_pathsays that it searches for an executable in path. Thefile.txtfile may not be (and it shouldn't be) an executable file, which is whysearch_pathis not seeing it.To find any file matching a particular name, disregarding whether the file is executable or not, you can use
std::filesystem::directory_iteratororstd::filesystem::recursive_directory_iteratorto write your own function to do that. Note thatstd::filesystemis only available starting from C++17. For older standards,boost::filesystemmay be used instead.