本文整理匯總了Golang中github.com/cloudfoundry/gunk/command_runner.CommandRunner類的典型用法代碼示例。如果您正苦於以下問題:Golang CommandRunner類的具體用法?Golang CommandRunner怎麽用?Golang CommandRunner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CommandRunner類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: New
func New(containerDepotPath, binPath string, runner command_runner.CommandRunner) (*LinuxQuotaManager, error) {
dfOut := new(bytes.Buffer)
df := &exec.Cmd{
Path: "df",
Args: []string{"-P", containerDepotPath},
Stdout: dfOut,
}
err := runner.Run(df)
if err != nil {
return nil, err
}
dfOutputWords := strings.Split(string(dfOut.Bytes()), " ")
mountPoint := strings.Trim(dfOutputWords[len(dfOutputWords)-1], "\n")
return &LinuxQuotaManager{
enabled: true,
binPath: binPath,
runner: runner,
mountPoint: mountPoint,
}, nil
}
示例2: NewBigApp
func NewBigApp(runner command_runner.CommandRunner, appPath string, sizeInMegabytes int) (*BigApp, error) {
tempDirName, err := ioutil.TempDir("", "big-app")
if err != nil {
return nil, err
}
cmd := &exec.Cmd{Path: "cp", Args: []string{"-r", appPath + "/", tempDirName}}
err = runner.Run(cmd)
if err != nil {
return nil, err
}
ddOutputArg := "of=" + tempDirName + "/payload"
ddCountArg := fmt.Sprintf("count=%d", sizeInMegabytes)
cmd = &exec.Cmd{Path: "dd", Args: []string{"if=/dev/urandom", ddOutputArg, ddCountArg, "bs=1048576"}}
err = runner.Run(cmd)
if err != nil {
return nil, err
}
return &BigApp{
Location: tempDirName,
runner: runner,
Name: "big-app-" + generator.RandomName(),
}, nil
}
示例3: run
func (c *BtrfsCleaningCake) run(runner command_runner.CommandRunner, cmd *exec.Cmd) (string, error) {
var buffer bytes.Buffer
cmd.Stdout = &buffer
if err := runner.Run(cmd); err != nil {
return "", err
}
return buffer.String(), nil
}
示例4: destroy
func (n *rule) destroy(chain string, runner command_runner.CommandRunner) error {
return runner.Run(exec.Command("/sbin/iptables", flags("-D", chain, n)...))
}