Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Output Redirection with UNIX System Calls

Output Redirection with UNIX System Calls
Thread Tools
Fresh-Faced Recruit
Join Date: Feb 2003
Location: West LA
Status: Offline
Reply With Quote
Oct 26, 2004, 04:52 AM
 
I'm writing a shell program for a CS class which needs to implement output redirection by messing around with the file descriptor table like this:

fid = open("output", O_CREAT|O_WRONLY);
close(1); //stdout
dup(fid);
close(fid);

For some reason this will create the file and not write anything to it, but if I execute the program using sudo it functions correctly. Is this some screwy thing having to do with UNIX and permissions or is there something wrong with the program itself?
     
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Oct 26, 2004, 08:03 AM
 
Sounds like the directory you're trying to write the output file to requires higher permissions than the normal user can provide, hence it working when you use sudo.

Try getting the program to write into your home directory without using sudo.
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
Fresh-Faced Recruit
Join Date: Feb 2003
Location: West LA
Status: Offline
Reply With Quote
Oct 26, 2004, 08:12 PM
 
Thanks for the suggestion. That actually wasn't it though. The call to open() takes an additional parameter that specifies the permissions of the created file. Without it my program was creating files without read/write/execute permissions, so only the superuser could access them.
     
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Oct 27, 2004, 08:27 AM
 
Oops! Oh well at least you figured it out which is the most important part!
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:58 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2