knqyf263 / pet

Simple command-line snippet manager
MIT License
4.41k stars 222 forks source link

Fix execution of command with quotes on windows. #238

Closed matrixx567 closed 7 months ago

matrixx567 commented 7 months ago

Issue

138

Description of changes:

Commands with quotes can't be handled on windows using standard exec.Command() calls. Based on the go documentation https://pkg.go.dev/os/exec#Command the argument handling is converted to SysProcAttr.

knqyf263 commented 7 months ago

thx

knqyf263 commented 7 months ago

I forgot to see the test result... it failed. @matrixx567 Could you take a look?

matrixx567 commented 7 months ago

@knqyf263 It seems that there is a problem with different operating systems. On my Windows machine all tests passes. The SysProcAttr.CmdLine will only be available on Windows.

I'm not so experienced in Go and I don't know how to handle these code lines only on the Windows system. Can you help me with that?

knqyf263 commented 7 months ago

SysProcAttr doesn't have a CmdLine field in Linux. https://github.com/golang/go/blob/f719d5cffdb8298eff7a5ef533fe95290e8c869c/src/syscall/exec_linux.go#L62-L108

We need to write different codes for different platforms with build constraints. https://github.com/golang/go/blob/f719d5cffdb8298eff7a5ef533fe95290e8c869c/src/syscall/exec_linux.go#L5