xclip not getting stdin from pexpect, or pexpect not sending?

122 views Asked by At

This

import pexpect

def run(cmd, stdin):
    child = pexpect.spawn(cmd, encoding='utf-8')
    child.send(stdin)
    child.sendeof()

run('xclip -selection clipboard', 'lol')

should copy string lol into my clipboard, so that I paste it around by Ctrl+v.

But, instead, I get the behaviour of echo -n '' | xclip -selection clipboard i.e. the behaviour of passing empty file as STDIN into xclip.

Why?


UPDATE

This prints lollxl instead of just lxl:

import pexpect

def run(cmd, stdin):
    child = pexpect.spawn(cmd, encoding='utf-8')
    child.send(stdin)
    child.sendeof()
    child.sendeof()
    x = child.read()
    child.wait()
    return x

x = run("sed --expression='s/o/x/g'", 'lol')
print(x)
0

There are 0 answers