...

Source file src/code.rocketnine.space/tslocum/desktop/run.go

Documentation: code.rocketnine.space/tslocum/desktop

     1  package desktop
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"os"
     7  )
     8  
     9  // RunScript creates a temporary run script consisting of a bash script which
    10  // removes itself and executes the specified command.
    11  func RunScript(exec string) (string, error) {
    12  	runScript, err := ioutil.TempFile("", "run-*")
    13  	if err != nil {
    14  		return "", err
    15  	}
    16  
    17  	_, err = runScript.WriteString("#!/bin/sh\n")
    18  	if err != nil {
    19  		runScript.Close()
    20  		return "", err
    21  	}
    22  	_, err = runScript.WriteString(fmt.Sprintf("rm %s\n", runScript.Name()))
    23  	if err != nil {
    24  		runScript.Close()
    25  		return "", err
    26  	}
    27  	_, err = runScript.WriteString("exec " + exec + "\n")
    28  	if err != nil {
    29  		runScript.Close()
    30  		return "", err
    31  	}
    32  
    33  	err = runScript.Close()
    34  	if err != nil {
    35  		return "", err
    36  	}
    37  
    38  	err = os.Chmod(runScript.Name(), 0744)
    39  	if err != nil {
    40  		return "", err
    41  	}
    42  
    43  	return runScript.Name(), nil
    44  }
    45  

View as plain text