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


Golang Session.StdinPipe方法代码示例

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


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

示例1: send_script

/*
	Expected to be invoked as a goroutine which runs in parallel to sending the ssh command to the
	far side. This function reads from the input buffer reader br and writes to the target stripping
	blank and comment lines as it goes.
*/
func send_script(sess *ssh.Session, argv0 string, env_file string, br *bufio.Reader) {

	target, err := sess.StdinPipe() // we create the pipe here so that we can close here
	if err != nil {
		fmt.Fprintf(os.Stderr, "unable to create stdin for session: %s\n", err)
		return
	}
	defer target.Close()

	if argv0 != "" {
		target.Write([]byte("ARGV0=\"" + argv0 + "\"\n")) // $0 isn't valid using this, so simulate $0 with argv0
	}

	if env_file != "" { // must push out the environment first
		env_file, err = find_file(env_file) // find it in the path if not a qualified name
		if err == nil {
			ef, err := os.Open(env_file)

			if err != nil {
				fmt.Fprintf(os.Stderr, "ssh_broker: could not open environment file: %s: %s\n", env_file, err)
			} else {
				ebr := bufio.NewReader(ef) // get a buffered reader for the file
				send_file(ebr, target)
				ef.Close()
			}
		} else {
			fmt.Fprintf(os.Stderr, "ssh_broker: could not find  environment file: %s: %s\n", env_file, err)
		}
	}

	send_file(br, target)
}
开发者ID:dhanunjaya,项目名称:gopkgs,代码行数:37,代码来源:ssh_broker.go

示例2: executeCommand

func (config *Config) executeCommand(s *ssh.Session, cmd string, sudo bool) ([]byte, error) {
	if s.Stdout != nil {
		return nil, errors.New("ssh: Stdout already set")
	}
	if s.Stderr != nil {
		return nil, errors.New("ssh: Stderr already set")
	}

	b := newSingleWriterReader()
	s.Stdout = &b
	s.Stderr = &b
	done := make(chan bool)

	if sudo {
		stdInWriter, err := s.StdinPipe()
		if err != nil {
			if config.AbortOnError == true {
				log.Fatalf("%s", err)
			}
			return nil, err
		}

		go config.injectSudoPasswordIfNecessary(done, &b, stdInWriter)
	}

	err := s.Run(cmd)
	close(done)
	return b.Bytes(), err
}
开发者ID:euforia,项目名称:loom,代码行数:29,代码来源:loom.go

示例3: remoteStandardio

func remoteStandardio(
	s *ssh.Session) (io.WriteCloser, io.Reader, io.Reader, string) {

	var stdin io.WriteCloser
	var stdout io.Reader
	var stderr io.Reader
	var err error

	// plumb into standard input
	if stdin, err = s.StdinPipe(); err != nil {
		return nil, nil, nil, fmt.Sprintf("Error: %v\n", err)
	}
	// plumb into standard output
	if stdout, err = s.StdoutPipe(); err != nil {
		return nil, nil, nil, fmt.Sprintf("Error: %v\n", err)
	}
	// plumb into standard error
	if stderr, err = s.StderrPipe(); err != nil {
		return nil, nil, nil, fmt.Sprintf("Error: %v\n", err)
	}
	return stdin, stdout, stderr, ""
}
开发者ID:prataprc,项目名称:gocbsh,代码行数:22,代码来源:client.go


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