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


Golang ProcAttr.Dir方法代码示例

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


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

示例1: trapSignal

// 处理系统信号
// 监听系统信号,重启或停止服务
func trapSignal(server client.Encoder) {
	sch := make(chan os.Signal, 10)
	signal.Notify(sch, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGINT,
		syscall.SIGHUP, syscall.SIGSTOP, syscall.SIGQUIT)
	go func(ch <-chan os.Signal) {
		sig := <-ch
		server.Shutdown("signal recieved " + sig.String() + ", at: " + time.Now().String())
		if sig == syscall.SIGHUP {
			server.Info("autoencode restart now...")
			procAttr := new(os.ProcAttr)
			procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
			procAttr.Dir = os.Getenv("PWD")
			procAttr.Env = os.Environ()
			process, err := os.StartProcess(os.Args[0], os.Args, procAttr)
			if err != nil {
				server.Info("autoencode restart process failed:" + err.Error())
				return
			}
			waitMsg, err := process.Wait()
			if err != nil {
				server.Info("autoencode restart wait error:" + err.Error())
			}
			server.Info(waitMsg)
		} else {
			server.Info("autoencode shutdown now...")
		}
	}(sch)
}
开发者ID:safeie,项目名称:autoencode-git,代码行数:30,代码来源:main.go

示例2: Open

func (s *Session) Open(t int) *Error {

	if s.IsOpen() {
		return nil
	}

	s.Type = t
	s.Args = s.BuildTranscodeCommand()
	log.Printf("Opening transcoder session: %s", s.Args)

	// create output directory structure
	if err := s.createOutputDirectories(); err != nil {
		return ErrorIO
	}

	// create pipe
	pr, pw, err := os.Pipe()
	if err != nil {
		s.setState(TC_FAILED)
		return ErrorTranscodeFailed
	}
	s.Pipe = pw

	// create logfile
	logname := s.c.Transcode.Log_path + "/" + s.idstr + ".log"
	s.LogFile, _ = os.OpenFile(logname, os.O_WRONLY|os.O_CREATE|os.O_APPEND, utils.PERM_FILE)

	// start transcode process
	var attr os.ProcAttr
	attr.Dir = s.c.Transcode.Output_path + "/" + s.idstr
	attr.Files = []*os.File{pr, s.LogFile, s.LogFile}
	s.Proc, err = os.StartProcess(s.c.Transcode.Command, strings.Fields(s.Args), &attr)

	if err != nil {
		log.Printf("Error starting process: %s", err)
		s.setState(TC_FAILED)
		pr.Close()
		pw.Close()
		s.LogFile.Close()
		s.Pipe = nil
		s.Type = 0
		s.Args = ""
		return ErrorTranscodeFailed
	}

	// close read-end of pipe and logfile after successful start
	pr.Close()
	s.LogFile.Close()

	// set timeout for session cleanup
	s.Timer = time.AfterFunc(time.Duration(s.c.Server.Session_timeout)*time.Second,
		func() { s.HandleTimeout() })

	// set state
	s.setState(TC_RUNNING)
	return nil
}
开发者ID:falahhaprak,项目名称:rter,代码行数:57,代码来源:session.go

示例3: exec

// 执行截图
func exec(url, pic, width, height, delay string) (string, error) {
	if url == "" {
		return "", errors.New("url is none.")
	}
	if width == "" {
		width = strconv.Itoa(conf.width)
	}
	if height == "" {
		height = strconv.Itoa(conf.height)
	}
	if delay == "" {
		delay = strconv.Itoa(conf.delay)
	}
	procAttr := new(os.ProcAttr)
	procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
	procAttr.Dir = os.Getenv("PWD")
	procAttr.Env = os.Environ()
	var args []string
	args = make([]string, 7)
	args[0] = PHANTOMJS
	args[1] = conf.dir + "/" + SNAP_JS
	args[2] = url
	args[3] = pic
	args[4] = delay
	args[5] = width
	args[6] = height
	process, err := os.StartProcess(PHANTOMJS, args, procAttr)
	if err != nil {
		if conf.debug == true {
			log.Println("PhantomJS start failed:" + err.Error())
		}
		return "", err
	}
	waitMsg, err := process.Wait()
	if err != nil {
		if conf.debug == true {
			log.Println("PhantomJS start wait error:" + err.Error())
		}
		return "", err
	}
	if conf.debug == true {
		log.Println(waitMsg)
	}
	return args[3], nil
}
开发者ID:safeie,项目名称:screenshot,代码行数:46,代码来源:main.go

示例4: Open

func (t *TranscodeSession) Open() error {

	if t.IsOpen() {
		return nil
	}

	if err := t.createOutputDirectories(); err != nil {
		log.Printf("Failed to create output directories: %s", err)
		return err
	}

	// create pipe
	pr, pw, err := os.Pipe()
	if err != nil {
		t.setState(TS_STATE_FAILED)
		return err
	}
	t.Pipe = pw

	// Start the transcode process
	attr := os.ProcAttr{}
	attr.Dir = filepath.Join(t.OutputDir, t.ID)
	attr.Files = []*os.File{pr}

	t.OutputFile = filepath.Join(t.OutputDir, t.ID, "index.m3u8")
	t.Proc, err = os.StartProcess("/usr/local/bin/ffmpeg", strings.Fields(t.buildTranscodeCommand()), &attr)
	if err != nil {
		log.Printf("Error starting process: %s", err)
		t.setState(TS_STATE_FAILED)
		pr.Close()
		pw.Close()
		t.Pipe = nil
		return err
	}

	// close the read-end fo the pipe after successful start
	pr.Close()

	// set state
	t.setState(TS_STATE_RUNNING)
	return nil
}
开发者ID:rharter,项目名称:mediaman,代码行数:42,代码来源:transcoder.go


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