Listener doesn't receive msgs if launchs Talker with system command
In the example in the tutorial of subscriber and listener everything works well, subscriber sends and listener receives messages. Using Linux, why if I launch the subscriber program from the listener with the command system in a new terminal, the listener doesn't receive any messages?
#include "ros/ros.h"
#include <std_msgs/Int32.h>
#include <signal.h>
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::Int32>("chat", 1);
ros::Rate loop_rate(1);
int count = 0;
while (ros::ok())
{
std_msgs::Int32 msg;
msg.data = getpid();
ROS_INFO("%i", msg.data);
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
LISTENER:
#include "ros/ros.h"
#include <std_msgs/Int32.h>
void chatterCallback(const std_msgs::Int32::ConstPtr& msg)
{
ROS_INFO("I heard: [%i]", msg->data);
}
int main(int argc, char **argv)
{
int status = system("gnome-terminal -x ./talker");
printf("STATUS: %d", status);
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chat", 1000, chatterCallback);
ros::Rate loop_rate(1);
int count = 0;
while (ros::ok())
{
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
STATUS:2
what happens if you do int status = system("gnome-terminal -x rosrun your_package talker");
With int status = system("gnome-terminal -x rosrun talker"); listener opens a new terminal, but appear the text "There was an error creating the child process for this terminal. Failed to execute child process "rosrun" (No such file or directory)" and two buttons on the right: "Profile Preferences" and Relaunch.