goc2p icon indicating copy to clipboard operation
goc2p copied to clipboard

示例代码无法运行的问题

Open TaoSunkist opened this issue 7 years ago • 3 comments

goc2p/src/multiproc/apipe/apipe.go demo2 为何会阻塞住?

TaoSunkist avatar May 12 '18 10:05 TaoSunkist

I encountered the same problem, and here was the solution: change the arg of "aux" to "au" or "x", both will work.

I am using Mac with OSX 10.13.4 version, zsh, Go1.8.1.

For further research, you can try:

  1. use different Go version. The first edition of this book uses Go1.3 while now the latest version of Go is 1.10
  2. OS aspects. Try Redhat / CentOS, try shell / bash, etc.

PS. here is the example code for the second edition of this book. https://github.com/gopcp/example.v2/blob/master/src/gopcp.v2/chapter3/apipe/apipe.go

我跟你遇到了同样的问题,目前查到的结果是:
把第一个命令 ps 的参数从 "aux"变成 "au"或者"x"就可以了,总之 "aux"不能同时出现。
我使用的环境是:
Macbook Pro,10.13.4,zsh,Go1.8.1 

下一步的调查方向:
1. Go的版本问题。作者写第一版书的时候用的是Go1.3版本,而我用的是1.8版本,现在最新的已经有1.10了。(1.8和1.9的表现也不一样)
2. 系统方面。可以试一试原生的 bash,或者 shell,然后试一试 Linux(Redhat or CentOS)等。

此外,可以看看这本书的第二版,代码更清晰,也没有问题。
https://github.com/gopcp/example.v2/blob/master/src/gopcp.v2/chapter3/apipe/apipe.go

danielsunzhongyuan avatar May 14 '18 05:05 danielsunzhongyuan

还有啊: 用 IDE(Gogland)去 Run 'go build apipe.go' 是不行的。但是直接用命令行 go run apipe.go 是可以的,而且,用命令行 go build apipe.go && ./apipe 也是可以的。

danielsunzhongyuan avatar May 14 '18 06:05 danielsunzhongyuan

今天看到这遇到了相同的问题,是代码有bug,在cmd2 start之前就向cmd2的stdin中写数据,数据无法被处理导致程序阻塞。 修改很简单,就是把写数据操作放在cmd2 start之后,已经提交了pull request https://github.com/hyper0x/goc2p/pull/19

met the same problem today. It outcomes a bug of the code. Because outputBuf1.WriteTo(stdin2) write output of command1 before commond2 start, and that will make the process block. You can see the change from my pull request, https://github.com/hyper0x/goc2p/pull/19

sunlianqiang avatar Jul 21 '19 15:07 sunlianqiang