I'm working on ROS MELODIC.

I would like to return as a service response a string containing a list of areas with some data. The problem here is that I wanted to format the output so on the client side, the message could be seen clear such as:

Area {i}: Data <...> 

Area {i}: Data <...>

I have tried either with normal string or array (string[])

So my problem here is that I can't print \n or something like that in order to see each element as a new line in the output on the client. I don't know if the problem is that this cannot be achieved through this (since the message response is printed as a list), or that I'm missing something.

Also, feel free to correct me if I didn't write my post correctly, I do want to check all the recommendations but I wanted to post this so I can get an answer as soon as possible.

  • $\begingroup$ Would it help to store the data in the string as json, then pretty print it on the receiving side using the built in json formatting options? $\endgroup$ Sep 8, 2023 at 13:30
  • $\begingroup$ Hello Lucas, thanks for the answer. As I said to lazylace, the idea was to somehow format how the rosservice call output is prompted in the client terminal (I didn't create any client because I was just checking the funcionality of the service). I imagine that there's no gap on how rosservice call outputs the services response, just the fields that the response contains, but thank you for the answer! $\endgroup$
    – ÁngeLoGa
    Sep 12, 2023 at 6:44
  • $\begingroup$ What do you see when you have \n in your text response- does it print out as \\n? $\endgroup$ Sep 13, 2023 at 14:00

1 Answer 1


In general, it is preferred to create a new Message type, in your case something like Area.msg, and in your Service return a list of Areas.
Then, in your client, you can print it out as you wish.

You should be able though to send and print strings with new lines; remember, if your Service type looks like this:

string areas

then you need to print the areas variable:

  • $\begingroup$ Thanks for the answer, I forgot to say I wanted to know if I could somehow format the message output from calling the service from the terminal with rosrun call. This is just for debugging cases, so I didn't want to create any client node or something like it, but maybe that's the way to go. $\endgroup$
    – ÁngeLoGa
    Sep 11, 2023 at 8:27
  • $\begingroup$ @ÁngeLoGa ROS messages are printed to the console as YAML, as explained here. That means you can pipe the rosservice output to tools like yq in Linux, here are some examples. $\endgroup$
    – lazylace
    Sep 14, 2023 at 12:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.