Topic
  • 5 replies
  • Latest Post - ‏2013-07-15T06:21:27Z by 101Rani
PaulClarke
PaulClarke
3 Posts

Pinned topic Querying program path

‏2013-06-09T08:44:01Z |

I have a program which runs on multiple platforms, windows, Linux, AIX etc, and the program reads data from a configuration file. By default I want the configuration file to be in the same directory as the program itself. On the other platforms I can easily determine where the program is running from but for the life of me I can't work out how to do it in AIX.

Can someone tell me how, in a running C program, you can ascertain the path to the program that is running ?

Thanks,

Paul

  • flodstrom
    flodstrom
    58 Posts

    Re: Querying program path

    ‏2013-06-10T15:55:45Z  

    It's no different than that of other UNIX's. Look at the man page for getcwd.

     

  • PaulClarke
    PaulClarke
    3 Posts

    Re: Querying program path

    ‏2013-06-10T16:03:47Z  
    • flodstrom
    • ‏2013-06-10T15:55:45Z

    It's no different than that of other UNIX's. Look at the man page for getcwd.

     

    I don't want the current working directory. I want the directory where the currently running program came from.

  • flodstrom
    flodstrom
    58 Posts

    Re: Querying program path

    ‏2013-06-10T16:55:25Z  

    I don't want the current working directory. I want the directory where the currently running program came from.

    Sorry, read that a bit to fast.

    I don't think there's any reliable way of finding out either the path or the name of a binary. The whole point is that a user shouldn't have to care about it. You can get some info from argv[0], but it's also deemed as unreliable by many programmers. Perhaps you can find something out from /proc (I have not looked into this on AIX though).

    I don't think there's an easy answer to this! I know not the answer you were looking for, but I would suggest to look at using some more conventional ways of finding that config file.

     

  • PaulClarke
    PaulClarke
    3 Posts

    Re: Querying program path

    ‏2013-06-10T17:00:40Z  
    • flodstrom
    • ‏2013-06-10T16:55:25Z

    Sorry, read that a bit to fast.

    I don't think there's any reliable way of finding out either the path or the name of a binary. The whole point is that a user shouldn't have to care about it. You can get some info from argv[0], but it's also deemed as unreliable by many programmers. Perhaps you can find something out from /proc (I have not looked into this on AIX though).

    I don't think there's an easy answer to this! I know not the answer you were looking for, but I would suggest to look at using some more conventional ways of finding that config file.

     

    Thanks for your response.

    Naturally I have tried argv[0] and looked in /proc and getprocs64() but none of them seem to tell me which program I am running.

    I agree that I could force the user to do some more configuration, setting environment variables or the like but it seemed unnecessary. Certainly on Windows and Linux etc one has no trouble finding out where the program is running from. It only seems on AIX that it is awkward (or in fact impossible).

    Cheers,

    Paul

  • 101Rani
    101Rani
    2 Posts

    Re: Querying program path

    ‏2013-07-15T06:21:27Z  

    Thanks for your response.

    Naturally I have tried argv[0] and looked in /proc and getprocs64() but none of them seem to tell me which program I am running.

    I agree that I could force the user to do some more configuration, setting environment variables or the like but it seemed unnecessary. Certainly on Windows and Linux etc one has no trouble finding out where the program is running from. It only seems on AIX that it is awkward (or in fact impossible).

    Cheers,

    Paul

    Hi,

    I am also doing the same thing..

    you can find attached file for reference.

    Attachments