dongsu1951 2014-09-09 03:00 采纳率: 0%
浏览 221

Windows命令行中Golang参数中的附加引号

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:

  • The reason I separate parameter and string combine it again, because command line need use unicode string such as Chinese String.
  • exiftool.exe only works on command line with "&#%d;" code with Chinese Character in Windows so I do more handle for this.
  • 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.

  • The Chinese word must change to &#%d; otherwise it will wrong display.
  • Even I tried it, but it still display extra " in my picture title.
  • 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))
    
  • 写回答

2条回答 默认 最新

  • du0173 2014-09-09 08:41
    关注

    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 世界.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致
  • ¥15 禅道二次开发编辑版本,上传不了发行包