Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dizzled

macrumors newbie
Original poster
May 31, 2006
8
0
Hey everyone,
I am fairly new to programming and Unix but i have a problem that is buggin me a bit. When I open up the terminal (I actually use iTerm, but I don't think there is much difference) I cd into the directory I will be working in. When I compile the executable gets put into the current directory (good) but when I run, my output data file gets put in my home directory (bad). This is very annoying and I can't figure out why it is doing this.

Also, can I make aliases to get me to my frequently used directories. All those cd <directory> commands are annoying. Thanks a lot everyone.
 

relimw

macrumors 6502a
May 6, 2004
611
0
SC
Hey everyone,
I am fairly new to programming and Unix but i have a problem that is buggin me a bit. When I open up the terminal (I actually use iTerm, but I don't think there is much difference) I cd into the directory I will be working in. When I compile the executable gets put into the current directory (good) but when I run, my output data file gets put in my home directory (bad). This is very annoying and I can't figure out why it is doing this.
Without knowing what the program is, this is almost impossible to answer why it would be doing that. You can try using redirection:
Code:
cat sometext.txt > here.txt

Also, can I make aliases to get me to my frequently used directories. All those cd <directory> commands are annoying. Thanks a lot everyone.
You can us links, it'll get rid of all those multiple directories you have to type to get places, but you still have to cd :)

Code:
ln -s /usr/bin/ mbin
This would drop a link named mbin in your local directory linked to /usr/bin/
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Hey everyone,
I am fairly new to programming and Unix but i have a problem that is buggin me a bit. When I open up the terminal (I actually use iTerm, but I don't think there is much difference) I cd into the directory I will be working in. When I compile the executable gets put into the current directory (good) but when I run, my output data file gets put in my home directory (bad). This is very annoying and I can't figure out why it is doing this.

Also, can I make aliases to get me to my frequently used directories. All those cd <directory> commands are annoying. Thanks a lot everyone.


Is it a C program? If so you can always use absolute paths in the names of your output files or use the function chdir() to change the working directory.

In Unix you can create soft links to files and directories. To create a soft link in your current directory to another directory or file use:-

Code:
ln -s path-to-the-directory

or

ln -s path-to-the-directory some-name-for-the-link

Do a 'man ln' for full details!

Anyway once you've create a soft link you can cd to it, list it etc.

Also, you might find the command line commands pushd and popd helpful.

b e n

EDIT: Sorry didn't read relimw's post fully! Excuse the repitition!
EDIT: Oops, didn't see the C++ in the title!
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
I would really use terminal ;), you can also set up aliases by editing the profile folder in your home directory (it's hidden but if it isn't there create one.)

This is mine:

Code:
#
# Your previous .profile  (if any) is saved as .profile.dpsaved
# Setting the path for DarwinPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

test -r /sw/bin/init.sh && . /sw/bin/init.sh
alias cdProg='cd ~/Documents/Programming/'
alias matlab='/Applications/Matlab_SV701/bin/matlab -nojvm'
alias sye='cd ~/documents/lecture\ courses/second\ year\ essay'
alias lc='cd ~/documents/lecture\ courses'
alias cprog='cd ~/documents/programming/c\ programming/'

Then I can type cprog in terminal and go to the C programming directory.
 

dizzled

macrumors newbie
Original poster
May 31, 2006
8
0
Without knowing what the program is, this is almost impossible to answer why it would be doing that. You can try using redirection:
Code:
cat sometext.txt > here.txt

Well, it does it with all of my programs. I have a file pointer and fprintf to the file. Do I need to close the file before I exit? Maybe that is why, that just occured to me. Anyway, I'll play around. Eraserhead, thank you for the profile code, that is exactly what I was looking for.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.