0

I am using system() to run some Unix commands from my application with code like the following:

std::stringstream command;

command << "rm -rf /some/directory";

int rmResult = system(command.str().c_str());

if (rmResult != 0) {
  clog << "Error: Failed to remove old output directory '" << command.str()
       << "' (" << errno << ") " << strerror(errno) << ".\n";
  throw;
}

However, while rmResult is zero and the rm works, I get this error in the console:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

What am I doing wrong, and how can I get this message to go away?

WilliamKF
  • 41,123
  • 68
  • 193
  • 295

1 Answers1

2

Apparently, this was due to having a directory that is now gone on my pushd stack, even though it was not the current working directory. Cleaning out my stack of the now gone directory, caused the messages to go away.

WilliamKF
  • 41,123
  • 68
  • 193
  • 295
  • yeah, I've seen this quirk before, and it seems to only happen when I would use certain shells. IIRC, this occurred for me in bash, but not tcsh. – Tim Jan 04 '11 at 03:36
  • @Tim I'm in bash, so that would seem to corroborate your recollection. – WilliamKF Jan 05 '11 at 03:14