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

Stdout for a subprocess when launching with --screen

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

nckswt gravatar image

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

I have the following three lines buried within a node (let's call it

    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, 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


--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 -0500 )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 -0500 )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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

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

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


@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 -0500 )edit

Question Tools



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

Seen: 712 times

Last updated: Jan 28 '17