ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to locate a non-executable generated file?

asked 2013-10-21 18:00:36 -0500

I have a catkin package which generates a file—it's not an executable, but some scripts I have need to be able to locate and read this file. It ends up by default in the build space, and I've set up a POST_BUILD command in CMakeLists.txt to copy it to the devel space. The $(find) macro (and rospack find) point back to the source tree, so that's no good for locating this file, and it's not executable, so rosrun isn't the right choice either.

Incidentally, it works great in install space, as the generated file just gets copied into the package's share directory like any other resource, and then rospack find does its thing.

I believe the $(find-resource) macro as discussed here does what I want, but only in the context of launch files, not from the command line. I'd prefer not to have to wrap this script in a launch file unless absolutely necessary.

It looks like under the hood, find-resource is implemented using the catkin.find_in_workspaces.find_in_workspaces function. Is there a commandline interface to this, or should I just write my own small python wrapper to do it?


edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2013-10-22 09:14:33 -0500

Dirk Thomas gravatar image

This functionality is already exposed in a command line tool called catkin_find. It has several option to customize your search.

edit flag offensive delete link more


Awesome, I'll switch to that on the next revision.

mikepurvis gravatar image mikepurvis  ( 2013-10-23 10:13:29 -0500 )edit

answered 2013-10-21 21:37:27 -0500

tfoote gravatar image

updated 2013-10-21 21:38:12 -0500

My understanding is that all generated files should get generated directly into devel. Do you generate the files after find_package(CATKIN)?

edit flag offensive delete link more


@Dirk Thomas please check my answer

tfoote gravatar image tfoote  ( 2013-10-21 21:38:18 -0500 )edit

answered 2013-10-22 08:53:59 -0500

For others in this position, here's my simple script:

#!/usr/bin/env python

import sys
from catkin.find_in_workspaces import find_in_workspaces

    script_name, package_name, file_name = sys.argv
except ValueError:
    sys.stderr.write("Usage: find_file PACKAGE FILE\n\n")

path = find_in_workspaces(project=package_name, path=file_name)

if len(path) > 0:
    sys.stdout.write("%s\n" % path[0])
    sys.stderr.write("No file found in package.\n")

Usage is:

rosrun mypkg find_file mypkg myfile
edit flag offensive delete link more


See @Dirk Thomas 's anwer catkin_find does this and more.

tfoote gravatar image tfoote  ( 2013-10-22 10:57:20 -0500 )edit

Question Tools

1 follower


Asked: 2013-10-21 18:00:36 -0500

Seen: 276 times

Last updated: Oct 22 '13