2016-10-15 76 views
0

同樣的問題在a question posted to the Unix & Linux StackExchange community更好的制定。代碼在Shell腳本運行之前其他操作

我編程,其在按鍵打開了一個腳本,打開一個新的終端(GNOME終端),運行scrot(截圖工具),可以用如下隨機名稱的圖片目錄,上傳它pomf。 cat並將鏈接複製到剪貼板。

這工作正常。現在我想要做的是上傳完成後關閉終端。

我的腳本是這樣工作的:

快捷方式(PrtScr) - >的gnome-terminal -e 「蟒蛇路徑/到/ script.py」 - >啓動Scrot - >保存文件(記住文件路徑) - > bash script2.sh path/to/picture - >上傳到pomf.cat - >獲取鏈接 - >通過「xclip -selection剪貼板」放入剪貼板

因爲我想在關閉終端後把字符串到剪貼板,我補充說:

eval $(printf $link | xclip -selection clipboard && sleep 1 && pkill terminal) 

這個問題是,沒有被複制到C脣膏和終端關閉。

然而,如果沒有「& &睡眠1 & & pkill的終端」的鏈接被複制,但在終端保持打開狀態。

在此先感謝。

//編輯

的第一個Script(運行scrot)

#!/usr/bin/env python 
import os 
import uuid 
import time 

def rstring(string_length=10): 
    random = str(uuid.uuid4()) 
    random = random.upper() 
    random = random.replace("-","") 
    return random[0:string_length] 

randomString = rstring(16) 

os.system("scrot -s -q 100 /home/timon/screenshots/" + randomString + ".jpg") 

while True: 
    processRead = os.popen("ps aux | grep \"scrot -s\" | cat").read() 
    if "scrot -s" not in processRead: 
     time.sleep(1) 
    else: 
     break 
     system.sleep(3) 

os.system("/home/timon/.screenshot_stuff/./screen.sh /home/timon/screenshots/" + randomString + ".jpg") 

第二個腳本(上傳截圖)

#!/usr/bin/env bash 

dest_url='https://cuntflaps.me/upload.php' 
return_url='https://a.cuntflaps.me' 

if [[ -n "${1}" ]]; then 
    file="${1}" 
    if [ -f "${file}" ]; then 
     printf "Uploading ${file}..." 
     my_output=$(curl --silent -sf -F files[]="@${file}" "${dest_url}") 
     n=0 # Multipe tries 
     while [[ $n -le 3 ]]; do 
      printf "try #${n}...\n" 
      if [[ true ]]; then 
       return_file=$(echo "$my_output" | grep "url" | sed 's/\,//g' | sed 's/\\//g' | sed 's/\"//g' | sed 's/\url://g' | tr -d ' ') 
       printf 'done.\n' 
       break 
      else 
       printf 'failed.\n' 
       ((n = n +1)) 
      fi 
     done 
      printf "$return_file" | xclip -selection clipboard && pkill terminal 
    else 
     printf 'Error! File does not exist!\n' 
     exit 1 
    fi 
else 
    printf 'Error! You must supply a filename to upload!\n' 
    exit 1 
fi 
+0

爲什麼你需要'eval'? – Leon

+0

這是用於運行命令,不是嗎? –

+0

不完全是,它是爲了增加額外的擴展/替代水平,這似乎是不需要你的情況。事實上,它甚至被錯誤地使用 - 它會嘗試以'$(...)'命令的輸出命令的形式運行。 – Leon

回答

1

所以最終我來到了我自己解。

這個問題似乎是xclip本身。 現在我使用「xsel --clipboard --input」,即使在直接退出後,它似乎也能正常工作。