Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission Denied Error

Status
Not open for further replies.

tewari68

Programmer
Jan 25, 2005
87
US
Hi,

I get the permission denied error while writing to a file, the code is

Code:
string fName = "/var/tmp/" + m_messageID + ".log";
ofstream dbfile1 (fName.c_str(), ios::app);
system("uname -n >> dbfile1");

the file fName already exists and contains some text.

Appreciate any help.

Thanks,
Tewari
 
What are the permissions on that file?
Are you the owner of the file?
 
> system("uname -n >> dbfile1");
This isn't the file you're writing to.

Code:
string cmd = "uname -n >> " + fName;
system( cmd.c_str() );

But you already have the file open with
ofstream dbfile1 (fName.c_str(), ios::app);
Which I think you should just delete from the code.

--
 
Hi Salem,
Your code works.
However I have one more problem in this case I am calling exim with -v option and want to redirect the output generated to the file.

Code:
string mailerSwitch1;
   string mailerSwitch2;
   string mSwitch;
   string switchOptn;
   string lessSign;
   string space;
   string systemCall;
   string Ch;
   const char * systemCallExec;

mailerSwitch1 = " -f ";
   mailerSwitch2 = " -v ";
   mSwitch = " -oMr";
   switchOptn = " processed";
   space = " ";
   lessSign = " < ";

systemCall = m_mailer + mailerSwitch2 + mailerSwitch1 + Ch + space + m_envelopTo + lessSign + finalEmailDestination;

string fname = "/var/tmp/" + m_msgid + ".log";
ofstream dbfile (fname.c_str(), ios::app);
               string cmd;
               cmd = systemCall + " >> " + fname;
               
               system(cmd.c_str());
Here the output still goes to the std out and not redirected to the file.
Can you suggest the changes.

THanks,
Tewari
 
> cmd = systemCall + " >> " + fname;
Print this out, to see what you have.

Then paste it into a console window - does it still not redirect properly, or does it do what you want?



--
 
Hi,
Ya I pasted it on the console window still the output goes to the stdout and not the file.

The call is to exim with -v -f option.

Code:
The systemCall looks like 
/var/exim -v -f abc@yahoo.com < /var/tmp/filename >> filename.log
 
Perhaps it's writing to stderr, rather than stdout.

If it is just stderr, then you can redirect this as well
Code:
/var/exim -v -f abc@yahoo.com < /var/tmp/filename >> filename.log 2>&1

Or if it's particularly poorly written, perhaps its writing directly to the terminal.

Does it look like normal text output (like you get from say 'ls'), or does it look like its using some kind of terminal control to give the impression of some kind of "windows" in a terminal environment (say split panes, input lines, menus etc).

--
 
Hi Salem,
Ya I overlooked that exim was writing to stderr not stdout with -v option.
Now it works fine.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top