zoukankan      html  css  js  c++  java
  • 源码 os.StartProcess exec.Command StartProcess is a low-level interface. The os/exec package provides // higher-level interfaces. 启动另一进程 命令行参数 第二个 CommandLine.Parse(os.Args[1:])

    Go/src/os/exec.go:96

    // StartProcess starts a new process with the program, arguments and attributes
    // specified by name, argv and attr. The argv slice will become os.Args in the
    // new process, so it normally starts with the program name.
    //
    // If the calling goroutine has locked the operating system thread
    // with runtime.LockOSThread and modified any inheritable OS-level
    // thread state (for example, Linux or Plan 9 name spaces), the new
    // process will inherit the caller's thread state.
    //
    // StartProcess is a low-level interface. The os/exec package provides
    // higher-level interfaces.
    //
    // If there is an error, it will be of type *PathError.
    func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error) {
    testlog.Open(name)
    return startProcess(name, argv, attr)
    }

    // Parse parses the command-line flags from os.Args[1:]. Must be called
    // after all flags are defined and before flags are accessed by the program.
    func Parse() {
    // Ignore errors; CommandLine is set for ExitOnError.
    CommandLine.Parse(os.Args[1:])
    }



    package main

    import (
    "flag"
    "fmt"
    "time"
    )

    func main() {
    var TaskType string
    flag.StringVar(&TaskType, "TASKTYPE", "TODO", "")
    flag.Parse()
    flag.Usage()
    fmt.Println("TASKTYPE",TaskType)
    for {
    fmt.Println("time", TaskType, " ---", time.Now())
    time.Sleep(16 * time.Second)

    }
    }
    go build -o TFlag.exe

    package main

    import (
    "fmt"
    "os"
    )

    func main() {
    p, e := os.StartProcess("TFlag.exe", []string{"CommandLine.Parse(os.Args[1:])","--TASKTYPE=TRAPCAP"}, &os.ProcAttr{Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}})
    fmt.Println(p, e)
    }








  • 相关阅读:
    如何监控IT正常运行时间?
    系统扩展正在取代macOS内核扩展,这会对您有何影响?
    IT管理员需要的10大网络工具
    自动化管理员工生命周期,集成Ultipro
    OpManager MSP:ManageEngine的新型MSP重点网络监控解决方案
    vue中axios的使用
    vue中axios的介绍
    移动端适配--关于根元素font-size和rem
    JavaScript---数组去重
    array数组的方法
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15513423.html
Copyright © 2011-2022 走看看