Rosanswers logo

So I tried to get my head arround how to best solve this problem but I'm probably missing a simple solution. i have a ros workspace. In this workspace I have multiple packages. And in each package I have probably multiple ros nodes.

Now what I want to do is I want to write a script that can get my all the nodes and possibly also all the publishers subscribers. Also if possible the parameters and services .

One idea of me was getting all the packages via the rospack list | workspace_name and that also works great to get the packages in the workspace.

But now the problem is how to I get all the publishers /subscribers. I know that I could get them online if the node is running via the rosnode command but how should I do this offline.

I hope I just overlooked something, I hope someone could help me what the offline methode for this is.

For additional information I'm working on ros Kinetic on Ubuntu 16.04.

Originally posted by Lycea on ROS Answers with karma: 15 on 2018-07-04

Post score: 1

Original comments

Comment by Delb on 2018-07-04:
Why do you want to do that ? Being "offline" means that you don't initialize your nodes and publishers/subscribers and everything else so you won't be able to find anything.

Comment by gvdhoorn on 2018-07-05:
I second the comment by @Delb: it would be good if you can provide some more context. Perhaps easier alternatives or more suitable approaches exist for what your ultimate goal is.


1 Answer 1


Rosanswers logo

I think grep is your best option. Navigate to the src directory of your Catkin workspace to issue these commands.

List Python and C++ nodes:

grep -Er "rospy.init_node|ros::init"

List Python and C++ subscribers:

grep -Er "rospy.Subscriber|.subscribe\("

List Python and C++ publishers:

grep -Er "rospy.Publisher|.advertise<"

List Python and C++ services:

grep -Er "rospy.Service\(|.advertiseService\("

Note that this assumes in Python you always call things relative to rospy. For C++ you could also grep on ros::Subscriber, ros::Publisher, and ros::ServiceServicer, but I did it the way I did so you can account for when you have separate header and source files - the commands I provide pick up on where the actual definition is provided.

Originally posted by adamconkey with karma: 642 on 2018-07-04

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by Lycea on 2018-08-07:
Thank you for that answer that was what I was searching for . I did it now in a kind of similar way to as you wrote. :)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.