You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
/**
|
|
= Creative Commons Lizenzvertrag =
|
|
ebktools von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
|
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
|
|
|
= Creative Commons License =
|
|
ebktools by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
|
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
|
**/
|
|
package ebkTools
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
)
|
|
|
|
//ExecuteCommandScriptHack() is necessary for too extensive shell commands, resulting in error 1 using exec.Command
|
|
func ExecuteCommandScriptHack(cmd *exec.Cmd, tmpDirPrefix, tmpScriptName string) (out []byte, err error) {
|
|
const (
|
|
binBash = "#!/bin/bash\n\n"
|
|
)
|
|
content := []byte(binBash + "\n\n" + cmd.String())
|
|
|
|
tmpdir, err := ioutil.TempDir("", tmpDirPrefix)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
//tmpfile, err := ioutil.TempFile(tmpdir)
|
|
//if err != nil {
|
|
// log.Fatal(err)
|
|
//}
|
|
//defer os.Remove(tmpfile.Name()) // clean up
|
|
|
|
tmpfn := filepath.Clean(tmpdir + "/" + tmpScriptName)
|
|
if err := ioutil.WriteFile(tmpfn, content, 0777); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer os.Remove(tmpfn) // clean up
|
|
|
|
newCmd := exec.Command(tmpfn)
|
|
out, err = newCmd.Output()
|
|
|
|
//fmt.Println(newCmd.String(), tmpdir, tmpfile.Name())
|
|
return
|
|
}
|