1 changed files with 50 additions and 0 deletions
@ -0,0 +1,50 @@ |
|||
/** |
|||
= 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 |
|||
} |
Loading…
Reference in new issue