Skip to content

Commit

Permalink
add python prefix for python scripts when there is no .py extension (#…
Browse files Browse the repository at this point in the history
…1589)

* add python prefix for python script when there is no .py extension

* consolidate and minimize change to existing code

* update comment

* revert unnecessary change from sys.platform to os.name
  • Loading branch information
kejxu authored and dirk-thomas committed Feb 6, 2019
1 parent 0648d30 commit 63989da
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/roslaunch/src/roslaunch/node_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ def create_local_process_args(node, machine, env=None):
if not cmd:
raise NodeParamsException("Cannot locate node of type [%s] in package [%s]"%(node.type, node.package))
cmd = [cmd]
if sys.platform in ['win32']:
if os.path.splitext(cmd[0])[1] == '.py':
cmd = ['python'] + cmd

# Python scripts in ROS tend to omit .py extension since they could become executable
# by adding a shebang line (#!/usr/bin/env python) in Linux environments
# special handle this case by executing the script with the Python executable in Windows environment
if sys.platform in ['win32'] and os.path.splitext(cmd[0])[1].lower() in ['.py', '']:
cmd = ['python'] + cmd
return _launch_prefix_args(node) + cmd + args

0 comments on commit 63989da

Please sign in to comment.