comparison src/ut/lu/lu.go @ 19:8008046c8d76

ut: add tee.
author pyon@macmini
date Sat, 23 Jun 2018 12:27:35 +0900
parents 45ca03520eea
children 4232b4cbeeb5
comparison
equal deleted inserted replaced
18:45ca03520eea 19:8008046c8d76
414 fmt.Printf( "%s:\t%x\n", file, h.Sum( nil ) ) 414 fmt.Printf( "%s:\t%x\n", file, h.Sum( nil ) )
415 } 415 }
416 } 416 }
417 } 417 }
418 418
419 /* tee: done. */
420 func Tee( file string ) {
421 if _, err := os.Stat( file ); !os.IsNotExist( err ) {
422 if err := os.Remove( file ); err != nil {
423 log.Fatal( err )
424 }
425 }
426 f, err := os.OpenFile( file, os.O_RDWR|os.O_CREATE, 0644 )
427 if err != nil {
428 log.Fatal( err )
429 }
430 defer f.Close()
431
432 w := io.MultiWriter( f, os.Stdout )
433 if _, err := io.Copy( w, os.Stdin ); err != nil {
434 log.Fatal( err )
435 }
436 }
437