开发者

Why does system() complain that cwd is not known?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜