Skip to content

Commit

Permalink
Fix copying a command to the clipboard on Linux.
Browse files Browse the repository at this point in the history
subprocess.Popen expects a sequence of program arguments. We split the commands using shlex, as the offical Python docs suggest. (http://docs.python.org/library/subprocess.html#popen-constructor)
  • Loading branch information
benvd committed Mar 13, 2012
1 parent 88ab2d7 commit a62a437
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/platform_utils.py
Expand Up @@ -6,6 +6,7 @@
import subprocess
import commands
import platform
import shlex
from terminalColor import color

class system:
Expand All @@ -24,15 +25,15 @@ def __init__(self):
self.copy_command = 'pbcopy'
else :
self.name = 'linux'
self.copy_command = 'xclip -selction clipboard'
self.copy_command = 'xclip -selection clipboard'

"""Copy given string into system clipboard."""
def copy(self,string):

# Assuming it works, we try and execute the function
worked = True
try:
subprocess.Popen([self.copy_command], stdin=subprocess.PIPE).communicate(str(unicode(string)))
subprocess.Popen(shlex.split(self.copy_command), stdin=subprocess.PIPE).communicate(str(unicode(string)))
except Exception, why:

# If it doesn't work return flase
Expand Down

0 comments on commit a62a437

Please sign in to comment.