gogoshell自己的命令管道

问题描述:

我试图用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)并行运行。那么我怎样才能在管道连续的地方编写命令。

gogo中的流水线(如bash)期望从标准输入中消耗数据并生成标准输出的数据。管道中的每个元素都作为一个单独的线程同时运行。

您示例中的'add'命令不会消耗或生成标准输入/输出数据,因此不适合在管道中运行。

如果您只是想让这些命令按顺序运行,请使用';'命令分隔符:

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