boost::process::search_path not finding file

563 views Asked by At

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.

1

There are 1 answers

2
kotatsuyaki On

Note: This answer did’t solve the author’s problem. See comments below.


The documentation for boost::process::search_path says that it searches for an executable in path. The file.txt file may not be (and it shouldn't be) an executable file, which is why search_path is 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_iterator or std::filesystem::recursive_directory_iterator to write your own function to do that. Note that std::filesystem is only available starting from C++17. For older standards, boost::filesystem may be used instead.