当前位置: 首页>>代码示例>>Golang>>正文


Golang Terminal.Write方法代码示例

本文整理汇总了Golang中code/google/com/p/go/crypto/ssh/terminal.Terminal.Write方法的典型用法代码示例。如果您正苦于以下问题:Golang Terminal.Write方法的具体用法?Golang Terminal.Write怎么用?Golang Terminal.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code/google/com/p/go/crypto/ssh/terminal.Terminal的用法示例。


在下文中一共展示了Terminal.Write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: HandleTerminalReading

func HandleTerminalReading(channel ssh.Channel, term *terminal.Terminal) {
	defer channel.Close()
	for {
		line, err := term.ReadLine()
		if err != nil {
			break
		}

		cmd_log := Command{Cmd: string(line)}

		if strings.Contains(string(line), "exit") {
			logfile.Println("[exit requested]")
			channel.Close()
		}

		if line == "passwd" {
			line, _ := term.ReadPassword("Enter new UNIX password: ")
			logfile.Println("[password changed]: " + line)
			line, _ = term.ReadPassword("Retype new UNIX password: ")
			logfile.Println("[password changed confirmation]: " + line)
			term.Write([]byte("passwd: password updated successfully\r\n"))
			cmd_log.Cmd += " " + line
		} else {
			term.Write(RunCommand(line))
		}
		cmd_log.Save()
		logfile.Println(line)
	}

}
开发者ID:oiooj,项目名称:ssh-passwd-honeypot,代码行数:30,代码来源:sshd.go

示例2: newStartedMongoState

// newStartedMongoState takes a term argument to have a context for printing
func (msh *mongoStateHolder) newStartedMongoState(replicaID, backupID, mongodPath, mongoPath, mountPath string,
	term *terminal.Terminal, driver *strata.Driver) (*mongoState, error) {

	mongoState := mongoState{}
	var err error
	mongoState.dbpath, err = ioutil.TempDir("", "mongoq_")
	if err != nil {
		return &mongoState, err
	}

	if err := driver.RestoreReadOnly(replicaID, backupID, mountPath, mongoState.dbpath); err != nil {
		return &mongoState, err
	}

	// Try to start mongod
	// Look for output text to determine success
	// If output text indicates that port is already in use, try another port
	for mongoState.mongod == nil {
		mongoState.mongod = exec.Command(mongodPath, "--port="+strconv.Itoa(msh.nextPort),
			"--dbpath="+mongoState.dbpath, "--storageEngine=rocksdb", "--rocksdbConfigString=max_open_files=10")

		mongodOut, err := mongoState.mongod.StdoutPipe()
		if err != nil {
			return &mongoState, err
		}
		defer mongodOut.Close()
		if err := mongoState.mongod.Start(); err != nil {
			return &mongoState, err
		}
		// Wait until mongod is ready to accept a connection
		for {
			buf := make([]byte, 10000)
			n, _ := mongodOut.Read(buf)
			term.Write(buf[:n]) // If there is a problem starting mongod, the user should see it and kill process
			rec := string(buf[:n])
			if strings.Contains(rec, "waiting for connections on port") {
				mongodOut.Close()
				break
			} else if strings.Contains(rec, "Address already in use for socket") {
				mongodOut.Close()
				if err := mongoState.mongod.Process.Kill(); err != nil {
					return &mongoState, err
				}
				mongoState.mongod = nil
				term.Write([]byte("MONGOQ Trying to start mongod again on another port\n"))
				msh.nextPort++
				break
			}
		}
	}

	mongoState.mongo = exec.Command(mongoPath, "--port="+strconv.Itoa(msh.nextPort))
	msh.nextPort++
	mongoState.mongoPty, err = pty.Start(mongoState.mongo)
	return &mongoState, err
}
开发者ID:naytzyrhc,项目名称:rocks-strata,代码行数:57,代码来源:mongoq.go

示例3: terminalMessage

func terminalMessage(term *terminal.Terminal, color []byte, msg string, critical bool) {
	line := make([]byte, len(msg)+16)[:0]

	line = append(line, ' ')
	line = append(line, color...)
	line = append(line, '*')
	line = append(line, term.Escape.Reset...)
	line = append(line, []byte(fmt.Sprintf(" (%s) ", time.Now().Format(time.Kitchen)))...)
	if critical {
		line = append(line, term.Escape.Red...)
	}
	line = appendTerminalEscaped(line, []byte(msg))
	if critical {
		line = append(line, term.Escape.Reset...)
	}
	line = append(line, '\n')
	term.Write(line)
}
开发者ID:copiesofcopies,项目名称:xmpp-client,代码行数:18,代码来源:ui.go

示例4: terminalMessage

func terminalMessage(term *terminal.Terminal, color []byte, msg string) {
	line := make([]byte, len(msg)+16)[:0]

	line = append(line, ' ')
	line = append(line, color...)
	line = append(line, '*')
	line = append(line, term.Escape.Reset...)
	line = append(line, []byte(fmt.Sprintf(" (%s) ", time.Now().Format(time.Kitchen)))...)

	for _, c := range msg {
		if (c < 32 || c > 126) && c != '\t' {
			line = append(line, '?')
		} else {
			line = append(line, byte(c))
		}
	}
	line = append(line, '\n')
	term.Write(line)
}
开发者ID:elimisteve,项目名称:xmpp-client,代码行数:19,代码来源:ui.go


注:本文中的code/google/com/p/go/crypto/ssh/terminal.Terminal.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。