當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Cmd.Start方法代碼示例

本文整理匯總了Golang中exec.Cmd.Start方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cmd.Start方法的具體用法?Golang Cmd.Start怎麽用?Golang Cmd.Start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在exec.Cmd的用法示例。


在下文中一共展示了Cmd.Start方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RunWithEnvAndWd

func RunWithEnvAndWd(command string, args []string, env []string, wd string) (proc *exec.Cmd, err os.Error) {
	//log.Println(command, args)
	//hho := exec.PassThrough
	args = prepend(args, command)
	env = mergeEnv(os.Environ(), env)

	binpath, err := findCmd(findEnv(env, "PATH"), command)
	if err != nil {
		return nil, err
	}

	cmd := new(exec.Cmd)
	cmd.Path = binpath
	cmd.Args = args
	cmd.Env = env
	cmd.Dir = wd
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout

	err = cmd.Start()
	if err != nil {
		log.Print("Error running command ", command, ": ", err, "\n")
		return nil, err
	}
	return cmd, nil
}
開發者ID:Epictetus,項目名稱:wfdr,代碼行數:26,代碼來源:osutil.go

示例2: StdExecve

func StdExecve(argv []string, stopOnTrouble bool) bool {

	var err os.Error
	var cmd *exec.Cmd

	switch len(argv) {
	case 0:
		if stopOnTrouble {
			log.Fatalf("[ERROR] len(argv) == 0\n")
		}
		return false
	case 1:
		cmd = exec.Command(argv[0])
	default:
		cmd = exec.Command(argv[0], argv[1:]...)
	}

	// pass-through
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.Stdin = os.Stdin

	err = cmd.Start()

	if err != nil {
		if stopOnTrouble {
			log.Fatalf("[ERROR] %s\n", err)
		} else {
			log.Printf("[ERROR] %s\n", err)
			return false
		}
	}

	err = cmd.Wait()

	if err != nil {
		if stopOnTrouble {
			log.Fatalf("[ERROR] %s\n", err)
		} else {
			log.Printf("[ERROR] %s\n", err)
			return false
		}
	}

	return true
}
開發者ID:ssrl,項目名稱:mgd,代碼行數:46,代碼來源:handy.go

示例3: ProcessRequest

func ProcessRequest(request DownloadRequest) {
	var tempFile string = MakeTempFileName(request.url, ".flv")
	var tempFileSansExtension string
	{
		pathDotIndex := strings.LastIndex(tempFile, ".")
		tempFileSansExtension = tempFile[0:pathDotIndex]
	}

	var cmd *exec.Cmd = MakeCommand(&request, tempFile)

	if cmd == nil {
		request.WriteError("forming the download command", nil)
		return
	}

	var proc *StdoutProcessor
	if pipe, e := cmd.StdoutPipe(); e != nil {
		request.WriteError("setting youtube-dl pipe", e)
		return
	} else {
		proc = NewStdoutProcessor(&pipe)
	}

	if e := cmd.Start(); e != nil {
		request.WriteError("running youtube-dl", e)
		return
	}

	var state DownloadState = kStarting
	var data map[string]interface{}
	var e os.Error

	for {
		status, e := proc.ParseOneStatusMessage()
		if e != nil {
			if state < kExtractingAudio {
				request.WriteError("downloading the video", e)
				return
			} else {
				break
			}
		} else if status == nil {
			continue
		}

		if status.state != kDownloadingVideo && (status.state == 0 || status.state == state) {
			continue
		}

		fmt.Printf("Proc SM: %v\n", status)
		if status.state >= kDownloadingVideo && state != status.state {
			if data, e = ReadJson(tempFile + ".info.json"); e != nil {
				request.WriteError("reading video JSON", e)
				return
			}
			status.title = data["title"].(string)
		}
		state = status.state

		status.requestId = request.id
		request.statusChannel <- *status
	}

	var finalFileBaseName = data["title"].(string) + "." + *outputFormat
	var finalFile = request.basePath + "/" + finalFileBaseName
	if _, e := CopyFile(finalFile,
		tempFileSansExtension+"."+*outputFormat); e != nil {
		request.WriteError("tagging", e)
		return
	}

	request.statusChannel <- StatusMessage{request.id, kTagging, "", "", 0, 0, 0, nil, ""}
	var c = exec.Command("lltag", "--yes", "-G", "--rename=%a/%t", finalFileBaseName)
	c.Dir = request.basePath
	out, ioError := c.StdoutPipe()
	if ioError != nil {
		request.WriteError("starting the tagger", ioError)
		return
	}

	var in io.WriteCloser
	in, ioError = c.StdinPipe()
	if ioError != nil {
		request.WriteError("starting the tagger", ioError)
		return
	}

	var link string
	if e = c.Start(); e != nil {
		request.WriteError("tagging", e)
		return
	} else {
		in.Write([]byte(strings.Repeat("y\n", 20)))
		outData, e := ioutil.ReadAll(out)
		if e != nil {
			request.WriteError("reading the tagger output", e)
			return
		}
		match := regexp.MustCompile("New filename is '([^\n]*)'\n").FindStringSubmatch(string(outData))
		fmt.Printf("out data: %s\n\nmatch: %v\n", string(outData), match)
//.........這裏部分代碼省略.........
開發者ID:areusch,項目名稱:ytd-server,代碼行數:101,代碼來源:worker.go


注:本文中的exec.Cmd.Start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。