doubt about ./a.out

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sridhard2406
    New Member
    • Dec 2007
    • 52

    doubt about ./a.out

    Hi All,
    When user complile the c file defaulty it creates a.out bin file. Why user needs to run a exe with ./a.out.

    please find my obervation below.

    It will temperary assign the absolute path name to PATH variable and execute the binary file.

    Please let me know, my observation is correct.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    Wrong forum I guess. Try linux or unix forum

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      This is probably a gcc question. I'm not sure what sirdhard is asking about but it might behoove him/her to read a bit more about GCC

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        Hello RedSon,
        Sorry, I just cant agree with you. This is quite a question, related with linux.

        In general case when we try to run a command say
        #ping 127.0.0.1

        what actually happen?
        Linux system find out the path of ping command(more over the executable of ping program) from 2 place
        1. /bin
        2. /usr/bin/
        3. /home/individualuser/bin (not every linux support it)

        but think this, say you have created an executable in /home/johny/my_prog/ name a.out

        now you are trying to run it.... what you did is
        #cd /home/johny/my_prog
        #a.out


        This wont work at all. cause kernel will look for the program in
        /bin/
        /usr/bin/
        /home/individualuser/bin (not every linux support it)


        Not in current directory
        so program wont get execute and make an error.
        But if you want to run a executable from anywhere in you system do either 2 of these
        1. run by entire path. i.e.
        /home/johny/my_prog/a.out
        2. or change current directory to /home/johny/my_prog/ and then
        #./a.out

        Regards,
        johny

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          Yes what you say is correct.

          I interpreted the OPs original question to be about trying to run the object file as an executable. Not a path issue.

          If they are trying to run a.out (if it is a file that can be "executed") then they will need to make sure it is on the path or call it directly.

          Keep in mind that . and sometimes .. are on the path so you can go to your build output directory and type ./a.out like johny says.

          Comment

          • sridhard2406
            New Member
            • Dec 2007
            • 52

            #6
            Thanks for all your reply.

            Comment

            Working...