Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid weird shell escaping issues by using a tempfile

  • Loading branch information...
commit 05c768675abfcd312c2f1563776bf4c93c4ffd66 1 parent 668deb9
@misfo authored
Showing with 6 additions and 4 deletions.
  1. +6 −4 shell_turtlestein.py
View
10 shell_turtlestein.py
@@ -1,4 +1,4 @@
-import os.path, pipes, re, subprocess
+import os.path, pipes, re, subprocess, tempfile
import sublime, sublime_plugin
from functools import partial
from sublime_readline import show_input_panel_with_readline
@@ -143,10 +143,12 @@ def on_done(self, cwd, cmd_str):
self.process_region(active_view, region, cwd, shell_cmd, cmd['output'])
else:
if input_regions:
- # Since Sublime's build system don't support piping to STDIN
- # directly, pipe the selected text via `echo`.
+ # Since Sublime's build system doesn't support piping to STDIN
+ # directly, use a tempfile.
text = "".join([active_view.substr(r) for r in input_regions])
- shell_cmd = "echo %s | %s" % (pipes.quote(text), shell_cmd)
+ temp = tempfile.NamedTemporaryFile()
+ temp.write(text.encode('utf8'))
+ shell_cmd = "%s < %s" % (shell_cmd, pipes.quote(temp.name))
exec_args = settings['exec_args']
exec_args.update({'cmd': shell_cmd, 'shell': True, 'working_dir': cwd})
Please sign in to comment.
Something went wrong with that request. Please try again.