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

Is there a way to write terminal commands within a ROS node?

asked 2016-11-10 05:19:46 -0600

Marcofon gravatar image

updated 2016-11-11 03:31:51 -0600

gvdhoorn gravatar image

Hello, I'll try to be clear. I want to build a ROS node in which some code will execute terminal commands without the user input. In fact i have a script that does some elaborations to .txt files and that takes only terminal (I'm on Ubuntu) commands to do its elaborations. For example, this is how i call the script from a terminal window:

get_hrv -R test.txt

So, what i want, it's a node that will have, for example, this piece of code above nested in some ROS code, so the terminal window with the results of the elaboration will show up when I'll run the node. I hope that it's all clear, let me know if you need a better explanation. Maybe, there is a ROS package that does the job that i want, i don't know, I'm searching it. Thank you in advance for your help!


Edit: Many thanks to both of you. In fact, since i'm using C++, i just used the code

system("get_hrv -R test.txt");

and all went fine! Thank you again and sorry for my bad knowledge of programming languages, i must use ROS and so on because i'm doing a project for my university, but i come from a completely different field, since i'm a mechanical engineer. Thank you!!!

edit retag flag offensive close merge delete


@Marcofon: could I ask you to please not post answers unless you are actually answering a question? ROS Answers is slightly different from a 'normal' forum.

If any of the answers posted by @rbbg or @Airuno2L answered your question, could you please mark it as such by ticking the checkmark? Thanks!

gvdhoorn gravatar image gvdhoorn  ( 2016-11-11 03:34:29 -0600 )edit

Ok, i'm very sorry! No problem!

Marcofon gravatar image Marcofon  ( 2016-11-11 04:02:56 -0600 )edit

No need to apologise. Just keep it in mind.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-11 05:35:53 -0600 )edit

Sure! Of course!

Marcofon gravatar image Marcofon  ( 2016-11-11 06:00:09 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-11-10 06:52:34 -0600

Airuno2L gravatar image

There is nothing in ROS that prevents you from doing what you would normally do with python or C++. For example in python you could simply do this:

import os
os.system('get_hrv -R test.txt')

(Just a note, os.system is easy to use but is slowly being replaced by subprocess which isn't as easy to use in my opinion but is more capable. The main point is like rbbg said, this is really a python or C++ question, the fact that you want to do it with ROS doesn't really change anything).

edit flag offensive delete link more


Thank you for your reply, the problem is that i'm not experienced with programming. For example i have never used python and i really don't know how implementing it in a ros node. More over, i must use c++ in my node, for other reasons. Can you help me with it?

Marcofon gravatar image Marcofon  ( 2016-11-10 09:09:06 -0600 )edit

answered 2016-11-10 06:31:59 -0600

rbbg gravatar image

Hi Marco,

The way to do this depends on your system and the language you use for writing your node and you don't need ROS to do so. Stackoverflow offers a number of options both for Python and C++.

edit flag offensive delete link more


Thank you. As i wrote it on the other comment, can you help me to implement the code i need ? I must use c++ and my OS is Ubuntu 14.04. Can you help me with a detailed explanation? Sorry if i'm stealing your time, but i'm afraid that i will get lost on asking or reading on stackoverflow.

Marcofon gravatar image Marcofon  ( 2016-11-10 09:11:59 -0600 )edit

Question Tools

1 follower


Asked: 2016-11-10 05:19:46 -0600

Seen: 1,390 times

Last updated: Nov 11 '16