#I am taking string from user input, how do I "convert" the string into exec.Command input?

35 messages · Page 1 of 1 (latest)

vernal dawn
#

Since exec.Command accepts name and args separately

#

And shell can additionally accept piping and stuff

torpid summit
vernal dawn
torpid summit
vernal dawn
#

@torpid summit How would I deal with pipes | in Go?

#

Crossplatform

torpid summit
#

unsure what you mean.

vernal dawn
torpid summit
#

but neither of those are go programs. Either way if you pipe something into an executable it gets read as input you can scan

vernal dawn
#

exec.Command(...)

#

But it wouldnt because I am calling strings.Fields on it

torpid summit
#

I would think you can still do pipes

vernal dawn
#

strings.Fields basically just splits them

#

[]string{"find", "|", ...}

#

passing that wouldnt work

torpid summit
#

why not

#

I have no idea is the first thing I'm just guessing

scarlet smelt
#

| 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

scarlet smelt
#

that's what | does at the end of the day: wires up one program's stdout to the next program's stdin

vernal dawn
#

The user provides the input

#

It could be echo "..." | fd | something | fzf

vernal dawn
#

And construct Cmd for each?

scarlet smelt
#

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

viral shale
#

brute force way is use ["/bin/sh" "-c", str]

vernal dawn
viral shale
#

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

vernal dawn
#

Fuck it, I am just gonna hide and delete the project