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


Golang Cmd.Args方法代碼示例

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


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

示例1: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	if *version {
		fmt.Printf("%s", Version)
		os.Exit(0)
	}

	if *unset != "" {
		os.Unsetenv(*unset)
	}

	cmd := new(exec.Cmd)
	cmd.Env = env

	// Check for "-" as an argument, because it means the same as "-i"
	if flag.Arg(0) == "-" {
		cmd.Env = make([]string, 0)
	}

	for i, arg := range flag.Args() {
		if strings.Index(arg, delim) > 0 {
			cmd.Env = append(cmd.Env, arg)
		} else if arg != "-" {
			if *nullEol {
				fatal.Fatalln("cannot specify --null (-0) with command")
			}

			cmd.Path = arg

			cmd.Args = append(cmd.Args, flag.Args()[i:]...)
			cmd.Stdin = os.Stdin
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr

			err := execvp(cmd)
			if err != nil {
				fatal.Fatalln(err)
			}
			return
		}

		i++
	}

	eol := '\n'
	if *nullEol {
		eol = '\x00'
	}

	for _, e := range env {
		fmt.Printf("%s%c", e, eol)
	}

	return
}
開發者ID:postfix,項目名稱:go-coreutils,代碼行數:60,代碼來源:env.go

示例2: add

// stem words and add them to vocabulary
func (vocabulary Dictionary) add(words []string, mode string) (wordIDs []int) {
	var lemma string
	wordIDs = make([]int, len(words))
	for idx, word := range words {
		if _, ok := vocabulary.Vtoi[word]; ok {
			wordIDs[idx] = vocabulary.Vtoi[word]
		} else {
			python := new(exec.Cmd)
			args := []string{"lemmatizer.py", "--vocabulary"}
			args = append(args, word)
			args = append(args, "--pos")
			args = append(args, mode)
			python.Args = args
			//       python.Path = "/home/lea/Code/Python/lemmatizer.py"
			python.Path = "/local/lea/thesis/python/lemmatizer.py"
			out, _ := python.Output()
			lemma = strings.Trim(string(out), "\n")
			if _, ok := vocabulary.Vtoi[lemma]; !ok {
				vocabulary.VList[vocabIdx] = lemma
				vocabulary.Vtoi[lemma] = vocabIdx
				vocabulary.Itov[vocabIdx] = lemma
				vocabulary.POSList[vocabIdx] = mode
				vocabIdx++
			}
			wordIDs[idx] = vocabulary.Vtoi[lemma]
		}
	}
	return wordIDs
}
開發者ID:ColiLea,項目名稱:ScriptModeling,代碼行數:30,代碼來源:createVocabulay.go

示例3: RunWithEnvAndWd

func RunWithEnvAndWd(command string, args []string, env []string, wd string) (proc *exec.Cmd, err 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:crazy2be,項目名稱:osutil,代碼行數:26,代碼來源:osutil.go

示例4: Launch

// Launch creates and begins debugging a new process. First entry in
// `cmd` is the program to run, and then rest are the arguments
// to be supplied to that process.
func Launch(cmd []string) (*Process, error) {
	var (
		proc *exec.Cmd
		err  error
	)
	// check that the argument to Launch is an executable file
	if fi, staterr := os.Stat(cmd[0]); staterr == nil && (fi.Mode()&0111) == 0 {
		return nil, NotExecutableErr
	}
	dbp := New(0)
	dbp.execPtraceFunc(func() {
		proc = exec.Command(cmd[0])
		proc.Args = cmd
		proc.Stdout = os.Stdout
		proc.Stderr = os.Stderr
		proc.SysProcAttr = &syscall.SysProcAttr{Ptrace: true, Setpgid: true}
		err = proc.Start()
	})
	if err != nil {
		return nil, err
	}
	dbp.Pid = proc.Process.Pid
	_, _, err = dbp.wait(proc.Process.Pid, 0)
	if err != nil {
		return nil, fmt.Errorf("waiting for target execve failed: %s", err)
	}
	return initializeDebugProcess(dbp, proc.Path, false)
}
開發者ID:alexbrainman,項目名稱:delve,代碼行數:31,代碼來源:proc_linux.go

示例5: pluginInfo

func pluginInfo(name string) (ver, short, long string) {
	if os.Getenv("HKPLUGINMODE") == "info" {
		return "", "plugin exec loop", "plugin exec loop"
	}
	short = "no description"
	long = name + ": unknown description"
	var cmd exec.Cmd
	cmd.Args = []string{name}
	cmd.Path = lookupPlugin(name)
	cmd.Env = append([]string{"HKPLUGINMODE=info"}, os.Environ()...)
	buf, err := cmd.Output()
	if err != nil {
		return
	}
	info := string(buf)
	if !strings.HasPrefix(info, name+" ") {
		return
	}
	info = info[len(name)+1:]
	i := strings.Index(info, ": ")
	if i < 0 {
		return
	}
	ver, info = info[:i], info[i+2:]
	i = strings.Index(info, "\n\n")
	if i < 0 || 50 < i || strings.Contains(info[:i], "\n") {
		return
	}
	short, long = info[:i], info[i+2:]
	return ver, strings.TrimSpace(short), strings.TrimSpace(long)
}
開發者ID:shaunduncan,項目名稱:hk,代碼行數:31,代碼來源:plugin.go

示例6: pluginInfo

func pluginInfo(name string) (ver, short, long string) {
	if os.Getenv("HKPLUGINMODE") == "info" {
		return "", "[plugin exec loop]", "[plugin exec loop]\n"
	}
	var cmd exec.Cmd
	cmd.Args = []string{name}
	cmd.Path = lookupPlugin(name)
	cmd.Env = append([]string{"HKPLUGINMODE=info"}, os.Environ()...)
	buf, err := cmd.Output()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return "", "[unknown description]", "[unknown description]\n"
	}
	info := string(buf)
	if !strings.HasPrefix(info, name+" ") {
		return "", "[unknown description]", "[unknown description]\n"
	}
	info = info[len(name)+1:]
	i := strings.Index(info, ": ")
	ver, info = info[:i], info[i+2:]
	i = strings.Index(info, "\n\n")
	short, long = info[:i], info[i+2:]
	if len(short) > 50 || strings.Contains(short, "\n") {
		return "", "[unknown description]", "[unknown description]\n"
	}
	return ver, short, long
}
開發者ID:uriel,項目名稱:hk,代碼行數:27,代碼來源:plugin.go

示例7: runScript

func runScript(watcher *fsnotify.Watcher, interval int, command string) {
	for {
		now := time.Now()
		select {
		case event := <-watcher.Events:
			if time.Since(now) > time.Duration(interval)*time.Millisecond {
				if event.Op >= 1 && !strings.HasPrefix(event.Name, ".") {
					clear()
					var cmd *exec.Cmd
					commands := strings.Split(command, " ")
					// TODO: windows support
					name := commands[0]
					cmd = exec.Command(name)
					cmd.Args = commands
					cmd.Stdout = os.Stdout
					cmd.Stderr = os.Stderr
					err := cmd.Run()
					if err != nil {
						log.Println("error:", err)
					}
				}
				now = time.Now()
			}
		case err := <-watcher.Errors:
			log.Println("error:", err)
		}
	}
}
開發者ID:yosuke-furukawa,項目名稱:wt,代碼行數:28,代碼來源:wt.go

示例8: NewExecutablePlugin

// Initialize a new ExecutablePlugin from path to executable and daemon mode (true or false)
func NewExecutablePlugin(a Arg, path string) (*ExecutablePlugin, error) {
	jsonArgs, err := json.Marshal(a)
	if err != nil {
		return nil, err
	}
	// Init the cmd
	cmd := new(exec.Cmd)
	cmd.Path = path
	cmd.Args = []string{path, string(jsonArgs)}
	// Link the stdout for response reading
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return nil, err
	}
	// Init the ExecutablePlugin and return
	ePlugin := new(ExecutablePlugin)
	ePlugin.cmd = cmd
	ePlugin.stdout = stdout
	ePlugin.args = a
	ePlugin.stderr = stderr

	return ePlugin, nil
}
開發者ID:linearregression,項目名稱:snap,代碼行數:28,代碼來源:execution.go

示例9: execute

func execute(path string, vcs string, vcs_verb string) {
	if vcs_verb == "" {
		return
	}
	a := func(wd string, vcs string, vcs_verb string, seq bool) {
		msg := "=== @{!" + vcs_color[vcs] + "} "
		msg += filepath.Base(path)
		msg += "@| (@!" + vcs + "@|) ==="
		var cmd exec.Cmd
		cmd.Dir = wd
		cmd.Args = strings.Split(vcs_verb, " ")
		path, err := exec.LookPath(cmd.Args[0])
		if err != nil {
			path = cmd.Args[0]
		}
		cmd.Path = path
		out, err := cmd.CombinedOutput()
		if err != nil {
			br := color.Colorize("!r")
			rst := color.Colorize("|")
			fmt.Printf(color.Sprint(msg)+"\n%s\n%s%s%s\n\n", out, br, err, rst)
		} else {
			fmt.Printf(color.Sprint(msg)+"\n%s\n", out)
		}
		if !seq {
			quit <- 0
		}
	}
	if *sequential {
		a(path, vcs, vcs_verb, *sequential)
	} else {
		count += 1
		go a(path, vcs, vcs_verb, *sequential)
	}
}
開發者ID:tkruse,項目名稱:vcstool,代碼行數:35,代碼來源:vcstool.go

示例10: main

func main() {

	flag.Parse()

	data := Data{
		"SVG -> PDF",
		time.Now().Format("_2 Jan 2006 15:04:05"),
		20150803,
		"Строка кириллицей",
		true,
	}

	var err error

	// Load template from file
	template, err := template.ParseFiles(*inputFile)
	chk(err)

	// Store template to buffer
	buf := new(bytes.Buffer)
	err = template.Execute(buf, data)
	chk(err)

	// Convert via external application
	// Install before use
	// # apt-get install librsvg2-bin
	// or
	// # apt-get install inkscape
	var cmd *exec.Cmd

	if *converter == "inkscape" {
		fmt.Println("Generate via inkscape")
		cmd = exec.Command("inkscape", "--without-gui", "/dev/stdin", "--export-pdf=/dev/stdout")
		if *outputPng != "" {
			cmd.Args = append(cmd.Args, "--export-png", *outputPng)
		}
	} else {
		fmt.Println("Generate via rsvg-convert")
		cmd = exec.Command("rsvg-convert", "-f", "pdf")
	}
	cmd.Stdin = bytes.NewReader(buf.Bytes())

	// Write pdf to file
	out, err := os.OpenFile(*outputFile, os.O_CREATE|os.O_WRONLY, 0666)
	chk(err)
	defer out.Close()
	cmd.Stdout = out

	timeStart := time.Now().UnixNano()
	err = cmd.Run() // Syncronous run external application
	chk(err)
	timeEnd := time.Now().UnixNano()

	fmt.Println("Conversion time (ms)", (timeEnd-timeStart)/1000000)

	// Open output file using the OS's default application
	open.Run(*outputFile)

}
開發者ID:plumbum,項目名稱:go-samples,代碼行數:59,代碼來源:svgTemplateToPdf.go

示例11: Output

// Output runs p4 and captures stdout.
func (p *Conn) Output(args []string) ([]byte, error) {
	b := p.opts.Binary
	if !strings.Contains(b, "/") {
		b, _ = exec.LookPath(b)
	}
	cmd := exec.Cmd{
		Path: b,
		Args: []string{p.opts.Binary},
	}
	if p.opts.Address != "" {
		cmd.Args = append(cmd.Args, "-p", p.opts.Address)
	}
	cmd.Args = append(cmd.Args, args...)

	log.Println("running", cmd.Args)
	return cmd.Output()
}
開發者ID:hanwen,項目名稱:p4fuse,代碼行數:18,代碼來源:p4.go

示例12: makeArgs

func makeArgs(cmd *exec.Cmd, tagBuffer []*PackageInfo, count int) {
	cmd.Args = make([]string, 3+count)
	cmd.Args[0] = "--qf"
	cmd.Args[1] = rpmFormat
	cmd.Args[2] = "-q"
	for i := 0; i < count; i++ {
		cmd.Args[3+i] = tagBuffer[i].Name
	}
}
開發者ID:AAFC-MBB,項目名稱:rpmout,代碼行數:9,代碼來源:rpmout.go

示例13: PlayFile

func (mp *CustomMediaPlayer) PlayFile(file string) error {
	var command exec.Cmd
	command.Path = mp.Executable
	mp.Args[len(mp.Args)-1] = file
	command.Args = mp.Args

	command.Start()
	return nil
}
開發者ID:chrigrah,項目名稱:nextplz,代碼行數:9,代碼來源:generic_mp.go

示例14: resolve

func (r *RealCommandRunner) resolve(cmd *exec.Cmd) *exec.Cmd {
	originalPath := cmd.Path

	path, err := exec.LookPath(cmd.Path)
	if err != nil {
		path = cmd.Path
	}

	cmd.Path = path

	cmd.Args = append([]string{originalPath}, cmd.Args...)

	return cmd
}
開發者ID:WIZARD-CXY,項目名稱:golang-devops-stuff,代碼行數:14,代碼來源:command_runner.go

示例15: generateTags

func generateTags(cmd *exec.Cmd) int {
	color.NoColor = (optionIndex(cmd.Args, "--nocolor") > 0)
	cmd.Args = append(cmd.Args, "--null")

	stdout, err := cmd.StdoutPipe()
	check(err)

	scanner := bufio.NewScanner(stdout)
	scanner.Split(scanLinesAndNulls)

	var (
		line      []byte
		curPath   string
		groupIdxs []int
	)

	aliasFile := NewAliasFile()
	defer aliasFile.WriteFile()

	aliasIndex := 1

	err = cmd.Start()
	check(err)

	for scanner.Scan() {
		line = scanner.Bytes()
		if groupIdxs = lineNumberRe.FindSubmatchIndex(line); len(groupIdxs) > 0 {
			// Extract and tagged match
			aliasFile.WriteAlias(aliasIndex, curPath, string(line[groupIdxs[2]:groupIdxs[3]]))
			fmt.Printf("%s %s\n", tagPrefix(aliasIndex), string(line))
			aliasIndex++
		} else if groupIdxs = pathRe.FindSubmatchIndex(line); len(groupIdxs) > 0 {
			// Extract and print path
			curPath = string(line[groupIdxs[2]:groupIdxs[3]])
			curPath, err = filepath.Abs(curPath)
			check(err)
			fmt.Println(string(line[:groupIdxs[1]]))
		} else {
			fmt.Println(string(line))
		}
	}

	err = cmd.Wait()
	if err != nil {
		return 1
	}
	return 0
}
開發者ID:aykamko,項目名稱:tag,代碼行數:48,代碼來源:tag.go


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