Cross-posting this from stackoverflow
<http://stackoverflow.com/questions/39764600/getting-error-back-after-executing-a-shell-script-via-golang>
:-
I have a simple shell script (named copy.sh) which looks like below:-
#! /bin/sh
cp $1 $2
I did chmod 777 copy.sh.
I have a golang code which executes the above shell code:-
package main
import (
"fmt"
"os/exec")
func main() {
_, err := exec.Command("/Users/debraj/copy.sh", "/Users/debraj/temp.txt",
"/Users/debraj/gotest/").Output()
if err != nil {
fmt.Println("Failed to execute command " + err.Error())
return
}
fmt.Printf("\nCopy Successful - %v")}
The above code is showing be the below output:-
jabongs-MacBook-Pro-4:src debraj$ go run copyerr.go Failed to execute command
exit status 1
jabongs-MacBook-Pro-4:src debraj$
But the error I receive from shell script looks like below:-
jabongs-MacBook-Pro-4:~ debraj$ ./copy.sh /Users/debraj/temp.txt
/Users/debraj/gotest/
cp: /Users/debraj/gotest/temp.txt: Permission denied
Can someone let me know how how can I get the same error message that is
returned by the shell script?
If I don;t do chmod 777 copy.sh and the file has permission as below:-
jabongs-MacBook-Pro-4:~ debraj$ ls -la copy.sh -rw-r--r-- 1 debraj staff 21
Sep 29 13:28 copy.sh
Then the golang code gives the output as given by the shell script. Can
some also let me know why this is behaving like this?
I am on
- Golang 1.7
- Mac OS X 10.11.4
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.