本文整理汇总了Golang中exec.Command函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Command函数的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

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

示例1: RunExternalAndStdout

func RunExternalAndStdout(cmd, wd string, argv []string) (stdout []byte, err os.Error) {
    argv = SplitArgs(argv)
    var c *exec.Cmd
    if len(argv) > 0 {
        c = exec.Command(cmd, argv...)
    } else {
        c = exec.Command(cmd)
    }
    c.Dir = wd
    c.Env = os.Environ()

    bStdout := bytes.NewBuffer(nil)
    bStderr := bytes.NewBuffer(nil)
    c.Stdout = bStdout
    c.Stderr = bStderr

    err = c.Run()

    if wmsg, ok := err.(*os.Waitmsg); ok {
        if wmsg.ExitStatus() != 0 {
            err = os.NewError(fmt.Sprintf("command: %s %v\n%s\n", cmd, argv, bStderr.String()))
        } else {
            err = nil
        }
    } else {
        stdout = bStdout.Bytes()
    }
    return
}

开发者ID:wb253,项目名称:go-gb,代码行数:29,代码来源:runext.go

示例2: MoveChapter

func MoveChapter(source string, dest string, resize bool) {
    files, _ := ioutil.ReadDir(source)
    for _, v := range files {

        if !validImage(v.Name) {
            fmt.Println("ignorando " + source + "/" + v.Name)
            continue
        }
        newName := ClearPageName(v.Name)

        canResize, needR := needResize(source + "/" + v.Name)

        var err os.Error
        cmd := "/usr/local/bin/convert"

        if resize && canResize {
            if needR {
                _, err = exec.Command(cmd, "-resize", "900x1600", "-quality", "50", source+"/"+v.Name, dest+"/"+newName).CombinedOutput()
                fmt.Println("Recodificando e diminuindo " + source + "/" + v.Name + " para " + dest + "/" + newName)
            } else {
                _, err = exec.Command(cmd, "-quality", "50", source+"/"+v.Name, dest+"/"+newName).CombinedOutput()
                fmt.Println("recodificando " + source + "/" + v.Name + " para " + dest + "/" + newName)
            }
            if err != nil {
                fmt.Println("falha ao mover e recodificar arquivo " + source + "/" + v.Name + ": " + err.String())
                os.Exit(1)
            }
        } else {
            /*if canResize{
                fmt.Println("movendo " + source + "/" + v.Name + " para " + dest + "/" + newName)
            }else{
            }*/

            if ext := strings.ToLower(path.Ext(v.Name)); ext == ".png" {
                fmt.Println("não foi possível codificar, movendo " + source + "/" + v.Name + " para " + dest + "/" + newName)
                if err = os.Rename(source+"/"+v.Name, dest+"/"+newName); err != nil {
                    fmt.Println("falha ao mover " + source + "/" + v.Name + " para " + dest + "/" + newName + ": " + err.String())
                }

            } else {

                fmt.Println("recodificando " + source + "/" + v.Name + " para " + dest + "/" + newName)
                _, err = exec.Command(cmd, "-quality", "50", source+"/"+v.Name, dest+"/"+newName).CombinedOutput()

                if err != nil {
                    fmt.Println("não foi possível codificar, movendo " + source + "/" + v.Name + " para " + dest + "/" + newName)
                    if err = os.Rename(source+"/"+v.Name, dest+"/"+newName); err != nil {
                        fmt.Println("falha ao mover " + source + "/" + v.Name + " para " + dest + "/" + newName + ": " + err.String())
                    }
                }
            }
        }
        // time.Sleep(1000000000)
    }
}

开发者ID:khronnuz,项目名称:manga-processor,代码行数:55,代码来源:Main.go

示例3: MakeRaw

/*
Set the standard in and out screens to raw mode.
Always call ResetRaw() when you are done.

Post:
    ResetRaw() will reset standard in and out to pre-raw settings
*/
func MakeRaw() {
    c := exec.Command("stty", "raw")
    set_exec(c)
    c.Run()

    ResetRaw = func() {
        c := exec.Command("stty", "-raw")
        set_exec(c)
        c.Run()
    }
}

开发者ID:Altece,项目名称:Go-Go-Gadget-Repo,代码行数:18,代码来源:screen.go

示例4: OpenURL

func OpenURL(url string) os.Error {
    if runtime.GOOS == "windows" {
        return exec.Command("cmd.exe", "/C", "start "+url).Run()
    }

    if runtime.GOOS == "darwin" {
        return exec.Command("open", url).Run()
    }

    return exec.Command("xdg-open", url).Run()
}

开发者ID:ipeet,项目名称:camlistore,代码行数:11,代码来源:openurl.go

示例5: BenchmarkCFuseThreadedStat

func BenchmarkCFuseThreadedStat(b *testing.B) {
    log.Println("benchmarking CFuse")

    lines := GetTestLines()
    unique := map[string]int{}
    for _, l := range lines {
        unique[l] = 1
        dir, _ := filepath.Split(l)
        for dir != "/" && dir != "" {
            unique[dir] = 1
            dir = filepath.Clean(dir)
            dir, _ = filepath.Split(dir)
        }
    }

    out := []string{}
    for k, _ := range unique {
        out = append(out, k)
    }

    f, err := ioutil.TempFile("", "")
    CheckSuccess(err)
    sort.Strings(out)
    for _, k := range out {
        f.Write([]byte(fmt.Sprintf("/%s\n", k)))
    }
    f.Close()

    log.Println("Written:", f.Name())
    mountPoint, _ := ioutil.TempDir("", "stat_test")
    wd, _ := os.Getwd()
    cmd := exec.Command(wd+"/cstatfs", mountPoint)
    cmd.Env = append(os.Environ(), fmt.Sprintf("STATFS_INPUT=%s", f.Name()))
    cmd.Start()

    bin, err := exec.LookPath("fusermount")
    CheckSuccess(err)
    stop := exec.Command(bin, "-u", mountPoint)
    CheckSuccess(err)
    defer stop.Run()

    for i, l := range lines {
        lines[i] = filepath.Join(mountPoint, l)
    }

    // Wait for the daemon to mount.
    time.Sleep(0.2e9)
    ttl := 1.0
    log.Println("N = ", b.N)
    threads := runtime.GOMAXPROCS(0)
    results := TestingBOnePass(b, threads, ttl*1.2, lines)
    AnalyzeBenchmarkRuns(results)
}

开发者ID:CloudLife,项目名称:go-fuse,代码行数:53,代码来源:stat_test.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng