繁体   English   中英

从命令行将剪贴板内容传递给python脚本

[英]passing clipboard contents to python script run from the command line

我试图将剪贴板的内容作为python脚本的参数传递给Terminal 该脚本称为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 tabulate_from_cl.py | pbpaste 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM