如何解决是否有从StringStream读取输入的正确方法
我正在编写一个自定义bash,它以串行和并行方式执行命令。当我尝试向终端回显任何内容时,在行的末尾会有一个空格,这使我无法通过测试用例。我的过程命令方法中有错误:
Commands commandProcess(std::string line,bool parallel,bool single) {
// Create a list of commands to be returned if there
// is processing occurring.
Commands list; // vector of strings
// Set up a string stream to read the line
std::stringstream ss(line);
std::string cl = ""; // clean line
// While the string stream is still has unread info read
// through quotes and assign the commands to a list.
std::string temp = "";
while (ss >> std::quoted(temp)) {
cl += temp + " ";
list.push_back(temp);
}
boost::trim_right(cl);
std::cout << "Running: " << cl << std::endl;
// Run a one line argument
if (!parallel && single) {
ChildProcess cp;
cp.forkNexec(list);
std::cout << "Exit code: " << cp.wait() << std::endl;
}
return list;
}
除echo命令外,所有程序在我的程序中均正常运行。任何指导都非常感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。