You are not logged in.

#1 2011-03-23 02:08:09

bananaman
Member
Registered: 2009-06-24
Posts: 5

[Solved] a.out not recognizing the working directory

It's a little bit embarrassing because this issue doesn't seem terribly complicated, but I'm having trouble with executing the a.out file (Hello World) that gcc produces. I have to explicitly state the directory that a.out is in to run it, even though it's in the working directory. Other programs, such as Nano, recognize the working directory just fine and it is able to open files inside the working directory without having me explicitly state the full directory name.
Any help would be greatly appreciated.

Last edited by bananaman (2011-03-23 03:16:10)

Offline

#2 2011-03-23 02:40:02

sisco311
Member
From: Romania
Registered: 2008-05-23
Posts: 112

Re: [Solved] a.out not recognizing the working directory

If the command you want to run is not in one of the directories listed in the PATH environment variable, you have to specify the full or relative path to it.


don't drink unwashed fruit juice.
i never make predictions, especially about the future.

Offline

#3 2011-03-23 02:52:57

bananaman
Member
Registered: 2009-06-24
Posts: 5

Re: [Solved] a.out not recognizing the working directory

sisco311 wrote:

If the command you want to run is not in one of the directories listed in the PATH environment variable, you have to specify the full or relative path to it.

Thank you very much! Just to clarify, I should set my PATH variable in /etc/profile in order to have it set every time I login, correct?

Last edited by bananaman (2011-03-23 03:00:00)

Offline

#4 2011-03-23 03:11:51

sisco311
Member
From: Romania
Registered: 2008-05-23
Posts: 112

Re: [Solved] a.out not recognizing the working directory

The easiest and most secure way would be using the relative path to the executable:

./a.out

If you use a single directory for writing/testing your programs, you could add it to your user PATH. Not a major security risk, but if you do so, be careful what executables are in the dir.

~/.bashrc (or ~/.bash_profile):

[[ -d ~/cpp ]] && export PATH="$PATH:~/cpp"

Adding the current working directory to PATH is a security risk, so I wouldn't recommend it.

Last edited by sisco311 (2011-03-23 03:12:29)


don't drink unwashed fruit juice.
i never make predictions, especially about the future.

Offline

#5 2011-03-23 03:17:34

bananaman
Member
Registered: 2009-06-24
Posts: 5

Re: [Solved] a.out not recognizing the working directory

Ah okay, I think I'll just use the relative path. I appreciate the help.

Offline

Board footer

Powered by FluxBB