2014-04-02 47 views
1

我試圖將Terminal的剪貼板內容作爲參數傳遞給python腳本。該腳本被稱爲tabulate_from_cl.py,它只是打印它收到的參數。雖然沒有問題,執行有一個從pbpaste將剪貼板內容傳遞給從命令行運行的python腳本

# ------------------------ 
# 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變量,但什麼也沒得到所需的輸出。我正在嘗試做什麼?

回答

0

更改管執行爲:

python tabulate_from_cl.py | pbpaste 
+0

這是我試過的變體之一,但它返回以下錯誤:在<_io.TextIOWrapper名''BrokenPipeError(32,「破碎管」) =''mode ='w'encoding ='UTF-8'> ignored'' –

相關問題