示例#1
0
文件: spawn.go 项目: enova/tokyo
// Spawn a process
func (s *Spawner) spawn(i int) {
	s.procs <- i

	cmd := s.cmds[i]
	fmt.Fprintf(os.Stderr, "Spawning: %s\n", cmd)
	_, err := exec.Command("bash", "-c", cmd).Output()
	if err != nil {
		msg := fmt.Sprintf("Spawner could not run command: %s, %s\n", cmd, err.Error())
		s.errs[i] = msg
		alert.Cerr(msg)
	}

	_ = <-s.procs
	s.alive.Done()
}
示例#2
0
文件: cols.go 项目: enova/tokyo
func main() {
	args := args.New(os.Args)

	// Help
	if args.IsOn("h") {
		fmt.Fprintf(os.Stderr, usage())
		os.Exit(0)
	}

	// Read Columns
	var cols []uint32
	for a := 1; a < args.Size(); a++ {
		col := lax.ParseUint32(args.Get(a))
		if col <= 0 {
			alert.Cerr("Columns start at 1")
			os.Exit(1)
		}

		cols = append(cols, col-1)
	}

	// Skip Header Lines (Optional)
	var skip int

	// Option: -s (Skip One Header Line)
	if args.IsOn("s") {
		skip = 1
	}

	// Option: -s=N (Skip N Header Lines)
	if args.HasOpt("s") {
		skip = args.GetOptI("s")
	}

	// Read Stdin
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()

		// Skip Header
		if skip > 0 {
			skip--
			continue
		}

		var tokens []string

		if args.IsOn("space") {

			// Split By Whitespace
			tokens = strings.Fields(line)

		} else {

			// Split By Comma
			tokens = strings.Split(line, ",")

		}

		// Display Columns
		for i, col := range cols {
			if col < uint32(len(tokens)) {
				if i > 0 {
					fmt.Printf(" ")
				}
				fmt.Printf("%s", tokens[col])
			}
		}

		fmt.Println()
	}
}