Reputation: 7318
Why does Example one
copy hello world
to my clip board but not Example two
?
# Example one
subprocess.check_output(["echo", "hello world", "|", "clip"], shell=True, stderr=subprocess.STDOUT)
# Example two
subprocess.check_output(["echo", "hello \n world", "|", "clip"], shell=True, stderr=subprocess.STDOUT)
Another issues is that Example one
copies hello world with quotes around it like so:
"hello world"
So, how do I copy text with multiple lines into the clipboard without double-quotes?
Upvotes: 1
Views: 276
Reputation: 7318
As suggested by @eryksun, this solves the issue:
p = subprocess.Popen('clip.exe', stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
p.communicate('hello \n world')
p.wait()
Upvotes: 1