【问题标题】:passing clipboard contents to python script run from the command line将剪贴板内容传递给从命令行运行的 python 脚本
【发布时间】:2014-05-13 12:48:20
【问题描述】:

我正在尝试将Terminal 可用的剪贴板内容作为参数传递给python 脚本。该脚本称为tabulate_from_cl.py,它只是打印它接收到的参数。虽然它执行没有问题,但pbpaste 的输出没有迹象

# ------------------------
# tabulate_from_cl.py

import sys

def main(args):
    for each in args:
        print('arg: {}\n'.format(each))


if __name__ == "__main__":
    main(sys.argv[:])

# ------------------------ 


# lets say pbpaste contains the string 'I am residing on the clipboard'

# at the command line...
$ pbpaste | tabulate_from_cl.py


# actual output
/Users/myhomedirectroy/Desktop/tabulate_from_cl.py

# desired output
/Users/myhomedirectroy/Desktop/tabulate_from_cl.py
I am residing on the clipboard

对此我尝试了很多变体,包括将pbpaste 的内容放入一个shell 变量中,但没有产生所需的输出。我正在尝试做的事情可能吗?

【问题讨论】:

    标签: python macos command-line terminal pipe


    【解决方案1】:

    将管道执行更改为:

    python tabulate_from_cl.py | pbpaste 
    

    【讨论】:

    • 这是我尝试过的变体之一,但它返回以下错误:BrokenPipeError(32, 'Broken pipe') in <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'> ignored
    猜你喜欢
    • 2011-10-13
    • 2013-05-16
    • 2019-08-24
    • 2011-12-13
    • 2013-12-07
    • 2018-12-04
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多