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

Stdout for a subprocess when launching with --screen

asked 2017-01-27 15:50:23 -0600

nckswt gravatar image

updated 2017-01-28 11:30:24 -0600

I have the following three lines buried within a node (let's call it network_scanner.py):

    cmd = ["sudo", "iwlist", "wlan0", "scan"]
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    iwlist_output = proc.communicate()[0].decode('utf-8')

If I call my launch file (roslaunch network_scanner network_scanner.launch --screen), iwlist_output is completely empty.

If I run the node directly (rosrun network_scanner network_scanner.py), I get expected output in iwlist_output.

I'm assuming the problem is that proc is unable to provide output to stdout for some reason when I roslaunch my node. Shouldn't --screen fix that?

Edit: Question assumed that there was an issue with stdout, but that wasn't the issue. The problem was that cmd wasn't being properly called because of permissions. This post provides a solution.

edit retag flag offensive close merge delete

Comments

--screen redirects the output of your node; it shouldn't affect things that your node is running within subprocess.

ahendrix gravatar image ahendrix  ( 2017-01-27 23:24:33 -0600 )edit

I've seen some of the wifi scanning commands return different results on consecutive runs, so you may want to try multiple runs to confirm that this isn't just random behavior

ahendrix gravatar image ahendrix  ( 2017-01-27 23:25:53 -0600 )edit

I haven't encountered this particular issue, but I've successfully used commands.getstatusoutput(my_cmd_string) from the commands module within a ROS node without any problems. However, "Using the subprocess module is preferable to using the commands module."

spmaniato gravatar image spmaniato  ( 2017-01-28 09:30:34 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-01-28 11:19:08 -0600

nckswt gravatar image

Actually, turns out it's a problem with sudo rather than with stdout: I wasn't getting prompted to enter my password when using roslaunch, but I was with rosrun -- seems like the command might not have been run at all.

edit flag offensive delete link more

Comments

@ahendrix Your solution in this post seems like the best way forward. Thanks!

Edit: Fixed link

nckswt gravatar image nckswt  ( 2017-01-28 11:20:36 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-01-27 15:50:23 -0600

Seen: 747 times

Last updated: Jan 28 '17