MCPcopy Index your code
hub / github.com/SirVer/ultisnips / _run_shell_command

Function _run_shell_command

pythonx/UltiSnips/text_objects/shell_code.py:25–43  ·  view source on GitHub ↗

Write the code to a temporary file.

(cmd, tmpdir)

Source from the content-addressed store, hash-verified

23
24
25def _run_shell_command(cmd, tmpdir):
26 """Write the code to a temporary file."""
27 cmdsuf = ""
28 if platform.system() == "Windows":
29 # suffix required to run command on windows
30 cmdsuf = ".bat"
31 # turn echo off
32 cmd = "@echo off\r\n" + cmd
33 handle, path = tempfile.mkstemp(text=True, dir=tmpdir, suffix=cmdsuf)
34 os.write(handle, cmd.encode("utf-8"))
35 os.close(handle)
36 os.chmod(path, stat.S_IRWXU)
37
38 # Execute the file and read stdout
39 proc = Popen(path, shell=True, stdout=PIPE, stderr=PIPE)
40 proc.wait()
41 stdout, _ = proc.communicate()
42 os.unlink(path)
43 return _chomp(stdout.decode("utf-8"))
44
45
46def _get_tmp():

Callers 2

_get_tmpFunction · 0.85
_updateMethod · 0.85

Calls 1

_chompFunction · 0.85

Tested by

no test coverage detected