Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个当前正在执行的命令行 C 程序,并且我想在同一目录中读取文件或执行另一个二进制文件 - 我怎样才能找出那个目录?
请注意,我不是在寻找当前的工作目录。用户可能通过以下任何方式调用了我的原始程序(可能还有其他我不知道的方式)。
理想情况下,我正在寻找可以通过 MinGW 在 unix 系统和 windows 上运行的东西。
http://c-faq.com/osdep/exepath.html
根据 C FAQ 它不能可靠地完成
在没有 /proc/self/exe 的情况下查找当前可执行文件的路径
连接 getcwd() 和 dirname(argv[0])