I would like to write a batch helper in Windows (Windows 8.1 with Go 1.3.1) to using exiftool.exe.
The reason I to run command line in Go is I tried to access some EXIF information which I retrieval from other web side. I just want to write back to picture EXIF.
Here is my code segment.
str_abs, _ := filepath.Abs(target_path)
str_title := fmt.Sprintf("-title=\"%s\"", ext_str)
stdout, err := exec.Command("cmd", "/c", "exiftool.exe", str_title, "-E", str_abs).Output()
However I found there always a addtional quote will in parameter so the result will identical with:
exiftool.exe -title=""TITLE"" -E TARGET_FILE
Any idea how it happen? or any suggestion for how to handle parameter like this.
Note:
How ever it also happen error if I use non-unicode such as (title shows '1234' not 1234)
stdout, err := exec.Command("cmd", "/c", "exiftool.exe", "-title", "1234", str_abs).Output()
error code:Run command eror: exit status 1.
-----Update on 2014/09/10 for @VonC-------------------------------------------------
Hi VonC,
I tried to do the same thing as your provided code, but it not works for me. I am curious about command line code page, I tried it in 477(US) 950 (Big5) both not work for me.
There is two thing I would like to discuss.
My code sample as follow:
output, err := exec.Command(`d:\exiftool.exe`,
`-title="test 2世界"`,
//If it not trasnfer from 世界 -> 世界 it could not display correctly.
"-E", "test.jpg").CombinedOutput()
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(string(output))
I just tested:
output, err := exec.Command(`c:\prgs\exiftool-9.70\exiftool.exe`,
`-title="test 2 世界"`,
"-E", "test.jpg").CombinedOutput()
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(string(output))
And it seems to work just fine.
Note that exec.CombinedOutput()
allows to see a bit more than just "exit status 1
" in case of a problem.
A second call will dispay all EXIF matadata:
exec.Command(`c:\prgs\exiftool-9.70\exiftool.exe`, "test.jpg").CombinedOutput()
The title is the expected test 2 世界
.
fmt.Printf("%q", "somestring") => "somestring"