Fix for using Popen without shell=true for multi-part commands e.g. "emacs -nw"
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import shlex
|
||||||
import codecs
|
import codecs
|
||||||
import curses
|
import curses
|
||||||
import logging
|
import logging
|
||||||
@@ -512,14 +513,17 @@ class Terminal(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
pager = os.getenv('PAGER') or 'less'
|
pager = os.getenv('PAGER') or 'less'
|
||||||
|
command = shlex.split(pager)
|
||||||
try:
|
try:
|
||||||
with self.suspend():
|
with self.suspend():
|
||||||
p = subprocess.Popen([pager], stdin=subprocess.PIPE)
|
_logger.debug('Running command: %s', command)
|
||||||
|
p = subprocess.Popen(command, stdin=subprocess.PIPE)
|
||||||
try:
|
try:
|
||||||
p.communicate(data.encode('utf-8'))
|
p.communicate(data.encode('utf-8'))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
p.terminate()
|
p.terminate()
|
||||||
except OSError:
|
except OSError as e:
|
||||||
|
_logger.exception(e)
|
||||||
self.show_notification('Could not open pager %s' % pager)
|
self.show_notification('Could not open pager %s' % pager)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
@@ -550,14 +554,17 @@ class Terminal(object):
|
|||||||
_logger.info('File created: %s', filepath)
|
_logger.info('File created: %s', filepath)
|
||||||
|
|
||||||
editor = os.getenv('RTV_EDITOR') or os.getenv('EDITOR') or 'nano'
|
editor = os.getenv('RTV_EDITOR') or os.getenv('EDITOR') or 'nano'
|
||||||
|
command = shlex.split(editor) + [filepath]
|
||||||
try:
|
try:
|
||||||
with self.suspend():
|
with self.suspend():
|
||||||
p = subprocess.Popen([editor, filepath])
|
_logger.debug('Running command: %s', command)
|
||||||
|
p = subprocess.Popen(command)
|
||||||
try:
|
try:
|
||||||
p.communicate()
|
p.communicate()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
p.terminate()
|
p.terminate()
|
||||||
except OSError:
|
except OSError as e:
|
||||||
|
_logger.exception(e)
|
||||||
self.show_notification('Could not open file with %s' % editor)
|
self.show_notification('Could not open file with %s' % editor)
|
||||||
|
|
||||||
with codecs.open(filepath, 'r', 'utf-8') as fp:
|
with codecs.open(filepath, 'r', 'utf-8') as fp:
|
||||||
@@ -588,9 +595,11 @@ class Terminal(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
urlview = os.getenv('RTV_URLVIEWER') or 'urlview'
|
urlview = os.getenv('RTV_URLVIEWER') or 'urlview'
|
||||||
|
command = shlex.split(urlview)
|
||||||
try:
|
try:
|
||||||
with self.suspend():
|
with self.suspend():
|
||||||
p = subprocess.Popen([urlview], stdin=subprocess.PIPE)
|
_logger.debug('Running command: %s', command)
|
||||||
|
p = subprocess.Popen(command, stdin=subprocess.PIPE)
|
||||||
try:
|
try:
|
||||||
p.communicate(input=data.encode('utf-8'))
|
p.communicate(input=data.encode('utf-8'))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@@ -605,7 +614,8 @@ class Terminal(object):
|
|||||||
if code == 1:
|
if code == 1:
|
||||||
self.show_notification('No URLs found')
|
self.show_notification('No URLs found')
|
||||||
|
|
||||||
except OSError:
|
except OSError as e:
|
||||||
|
_logger.exception(e)
|
||||||
self.show_notification(
|
self.show_notification(
|
||||||
'Failed to open {0}'.format(urlview))
|
'Failed to open {0}'.format(urlview))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user