2014-09-10 65 views
0

我試圖用gogoshell添加一些控制檯命令 比如我創建命令添加並顯示gogoshell自己的命令管道

public void add(CommandSession commandSession, int i) { 
    List<Integer> il = commandSession.get("list"); 
    if (il == null) { 
     il = new ArrayList<Integer>(); 
     il.add(i); 
     commandSession.put("list",il) 
    } else { 
     il.add(i) 
    } 
} 
public void show(CommandSession commandSession) { 
    List<Integer> il = commandSession.get("list"); 
    il.foreach(System.out::println); 
} 

,當我使用他們喜歡

add 1 | add 2 | add 3 | add 4 | show 

我歌廳像

null pointer Exception 

1 
3 
4 
2 

我認爲這是因爲管道(add)並行運行。那麼我怎樣才能在管道連續的地方編寫命令。

回答

0

gogo中的流水線(如bash)期望從標準輸入中消耗數據並生成標準輸出的數據。管道中的每個元素都作爲一個單獨的線程同時運行。

您示例中的'add'命令不會消耗或生成標準輸入/輸出數據,因此不適合在管道中運行。

如果您只是想讓這些命令按順序運行,請使用';'命令分隔符:

g!加1;加2;加3;加4;顯示