Find the answer to your Linux question:
Results 1 to 3 of 3
i am at home with a windows xp home, and i am using putty terminal to access my linux mathlab account, my task is to compile and run a C ...
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Posts
    1

    Exclamation help with simple terminal commands

    i am at home with a windows xp home, and i am using putty terminal to access my linux mathlab account, my task is to compile and run a C program, called a.c,

    i used

    gcc -Wall -g -o mycode a.c

    to compile it into a mycode file

    now when i want to run it, i was told i had to use

    $ mycode
    or
    $ ./mycode

    but both of these dont work. How do i run the file now?

    thanks

  2. #2
    Linux Newbie tetsujin's Avatar
    Join Date
    Oct 2008
    Posts
    115
    Quote Originally Posted by sneaky666 View Post
    i am at home with a windows xp home, and i am using putty terminal to access my linux mathlab account, my task is to compile and run a C program, called a.c,

    i used

    gcc -Wall -g -o mycode a.c

    to compile it into a mycode file

    now when i want to run it, i was told i had to use

    $ mycode
    or
    $ ./mycode

    but both of these dont work. How do i run the file now?

    thanks
    What do you get when you run "ls -l mycode"? And were there any errors when you ran gcc?

    If you run "mycode", what the shell does is check the environment variable called PATH for a list of directories, and check each of those directories, in order, for an executable program called "mycode".

    In DOS, the current directory is normally on the PATH (automatically? I can't remember...) In Unix the current directory is normally not on the PATH. The reasoning behind not having the current directory on the PATH is so that the effect of commands isn't changed by what your current directory is. (For instance, if you go to a directory where someone else has created an executable, typing a command with the same name won't run that executable...) However, it is possible to add the current directory (identified as ".") to $PATH in unix.

    Running "./mycode" bypasses the PATH search and explicitly identifies the program you're trying to run. If your gcc command was successful, and if you're in the same directory you were in when you compiled, then it should work.

  3. #3
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,301
    Another possibility is that you need to make mycode executable. The following command will give the current user and their group total access to the file and anybody else read only access.

    Make sure you are in the mycode directory and run
    Code:
     chmod 0774 mycode
    then
    Code:
     ./mycode
    should execute it assuming the compilation went OK.

    [edit]That's zero seven seven four[/edit]
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...