0

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.

gam03
  • 76
  • 5
  • Since you mentioned that the bug exists only on “some systems”, on which systems does the bug show up? – kotatsuyaki Oct 23 '22 at 06:52
  • @kotatsuyaki I have only tested this on Windows systems, it seems to work on some, and not others. – gam03 Oct 23 '22 at 19:07

1 Answers1

0

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.

kotatsuyaki
  • 1,441
  • 3
  • 10
  • 17
  • Hm, I (pretty stupidly) changed it from an executable to a text file. I am indeed trying to find an executable, I'll edit the question. Sorry about that! – gam03 Oct 23 '22 at 06:11
  • 1
    @gam03 I see. I’ll leave this answer as-is as it may still help future readers. – kotatsuyaki Oct 23 '22 at 06:36