#I am taking string from user input, how do I "convert" the string into exec.Command input?
35 messages · Page 1 of 1 (latest)
you split up the user input into tokens separated by spaces
strings.Fields then?
that's what I'd do
unsure what you mean.
Like find | fzf
but neither of those are go programs. Either way if you pipe something into an executable it gets read as input you can scan
No I am calling that user input from my program
exec.Command(...)
But it wouldnt because I am calling strings.Fields on it
I would think you can still do pipes
strings.Fields basically just splits them
[]string{"find", "|", ...}
passing that wouldnt work
| is a shell feature. exec.Command runs programs directly, not through a shell. (you could call a shell with it if you really want, but you probably don't need to.) you can achieve something like a pipe by setting the Stdin of fzf's Cmd to the result of StdoutPipe from find's Cmd
Its arbitrary tho
Idk
that's what | does at the end of the day: wires up one program's stdout to the next program's stdin
I would assume I have to split this string by |
And construct Cmd for each?
you could do that. you're going to have to define what the syntax of the user input actually is, because there's no single shell syntax that every shell subscribes to
brute force way is use ["/bin/sh" "-c", str]
No windows support :(
your examples didn't look like windows (does windows | even work like unix?)
but there is same is windows proc thingie
via SysProcAttr *syscall.SysProcAttr
I believe
but if you're trying to make a unix-y shell on windows in go, then you need to do the hard way more or less
Fuck it, I am just gonna hide and delete the project