看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): Linux 編譯器: codeblocks 問題(Question): 我需要用程式fork一個child process parent 和child各開啟一個terminal 並且讓使用者在這兩個terminal輸入字串 然後用pipe的方式傳遞兩個terminal上的字串 目前我可以成功做到前兩行及pipe 但不知道該如何input/output字串在terminal上 有試過請教google大神,但好像因為關鍵字下不對查不到相關的資料 希望大大能提供我想法,感謝 我真的是新手... 程式碼(Code):(請善用置底文網頁, 記得排版) int main(void){ system("gnome-terminal"); pid_t pid=fprk(); if(pid<0){ cout<<"failed to fork"; }else if(pid==0){ //... }else{ //... } return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.169.88.99 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1491190119.A.D76.html
tuyutd0505: int main(int argc char *argv[]) 04/03 13:08
tuyutd0505: main 的參數是用來接受終端輸入的 例如 ./main.out -a 04/03 13:08
tuyutd0505: 123456 這樣 程式裡面就會接收到兩個字串 分別是 arg 04/03 13:08
tuyutd0505: v[0] = "-a" 以及 argv[1] = "123456" 並且 argc = 2 04/03 13:08
tuyutd0505: (參數數量) 04/03 13:08
tuyutd0505: 不知道這樣有沒有幫助到你 04/03 13:08
tuyutd0505: 手機推文自動斷行了Orz 04/03 13:10
tuyutd0505: 抱歉我修正一下 argv[0] 應該會是 "./main.out" 後面 04/03 14:20
tuyutd0505: 兩個(argv[1&2])依序才是上述 然後 argc 是 3 04/03 14:20
jerryh001: 我覺得原po要的是打開後通訊 不是啟動參數 04/03 17:50
brilliantl: 是的,是j大說的,不過也感謝t大的指教 04/03 18:46
hunandy14: 記得是 pip 才可以互傳,不過忘記用法了~搜看看 04/04 01:36
hunandy14: 兩個要是父子,如果是子子,好像要父當中介轉發 04/04 01:39
x000032001: 或許你需要一個pseudoterminal? 04/04 10:28
ronin728: 去找找看 "popen redirect" 的資料,應該會有你要的 04/04 13:00
ronin728: "popen stdin stdout process" 之類的也能找找看 04/04 13:09
sirusi: 你是要開2個terminal 然後A打字可以傳到B上 反之亦然嗎? 04/04 21:38
sirusi: 要顯示在螢幕上的話 可以用dup2()試試看 04/04 21:40
brilliantl: S大,你說的沒錯,但我現在好像卡在無法開兩個termina 04/05 19:19
brilliantl: l 04/05 19:19
sirusi: 開兩個terminal可以直接在linux上開 如果是兩個terminal要 04/06 15:46
sirusi: 溝通 就我知道的方法是簡單的client/server程式 04/06 15:46
sirusi: 這部分可能要查network/socket programming相關資料 04/06 15:47