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 ...
- 01-14-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 1
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
- 01-14-2011 #2
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.
- 01-14-2011 #3
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 runthenCode:chmod 0774 mycode
should execute it assuming the compilation went OK.Code:./mycode
[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.


Reply With Quote
