Skip to content

Commit

Permalink
Support checking a URDF given on stdin (#171)
Browse files Browse the repository at this point in the history
Makes it easier to pipe results from xacro, and matches urdfdom_py's behavior
Closes #170
  • Loading branch information
nickswalker authored Aug 28, 2023
1 parent b5fffec commit 6d3c5de
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions urdf_parser/src/check_urdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,27 @@ void printTree(LinkConstSharedPtr link,int level = 0)
int main(int argc, char** argv)
{
if (argc < 2){
std::cerr << "Expect URDF xml file to parse" << std::endl;
std::cerr << "Expect URDF xml file to parse. Use - for stdin" << std::endl;
return -1;
}

std::string xml_string;
std::fstream xml_file(argv[1], std::fstream::in);
while ( xml_file.good() )
if (strcmp(argv[1], "-") == 0)
{
std::string line;
std::getline( xml_file, line);
xml_string += (line + "\n");
// Read from stdin
for (std::string line; std::getline(std::cin, line);)
{
xml_string += (line + "\n");
}
} else
{
std::ifstream xml_file(argv[1]);
for (std::string line; std::getline(xml_file, line);)
{
xml_string += (line + "\n");
}
xml_file.close();
}
xml_file.close();

ModelInterfaceSharedPtr robot = parseURDF(xml_string);
if (!robot){
Expand Down

0 comments on commit 6d3c5de

Please sign in to comment.