为什么 system() 抱怨 cwd 未知?
我正在使用 system() 从我的应用程序运行一些 Unix 命令,代码如下:
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;
}
但是,虽然 rmResult 为零并且 rm 工作,但我在控制台中收到此错误:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
我做错了什么,以及如何得到这条消息要消失吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,这是因为我的 Pushd 堆栈上现在有一个目录已经消失,即使它不是当前的工作目录。清理我的堆栈中现在已经消失的目录,导致消息消失。
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.