diff --git a/realsense2_description/launch/launch_utils.py b/realsense2_description/launch/launch_utils.py index 2f65eeb220..10e43fb064 100644 --- a/realsense2_description/launch/launch_utils.py +++ b/realsense2_description/launch/launch_utils.py @@ -21,12 +21,13 @@ def to_urdf(xacro_path, parameters=None): * xacro_path -- the path to the xacro file * parameters -- to be used when xacro file is parsed. """ - urdf_path = tempfile.TemporaryFile(prefix="%s_" % os.path.basename(xacro_path)) + with tempfile.NamedTemporaryFile(prefix="%s_" % os.path.basename(xacro_path), delete=False) as xacro_file: + urdf_path = xacro_file.name # open and process file doc = xacro.process_file(xacro_path, mappings=parameters) # open the output file - out = xacro.open_output(urdf_path) - out.write(doc.toprettyxml(indent=' ')) + with open(urdf_path, 'w') as urdf_file: + urdf_file.write(doc.toprettyxml(indent=' ')) return urdf_path