Than you..
I surely need to beef-up my comprehension of what os.exec does vs what it 
does not.

On Wednesday, March 25, 2020 at 2:54:07 PM UTC-4, Kurtis Rader wrote:
>
> The exec.Command() function works fine. The problem lies in your 
> understanding of what happens when you use a shell to execute that command 
> versus what the Go function does. When you type that command at a shell 
> prompt it parses the statement and creates a pipe and runs "echo" on the 
> LHS and "xsel" on the RHS of the pipe. The exec.Command() function does 
> none of that work. It simply runs an external program named "echo" with the 
> two arguments you provided. In other words it is as if you typed the 
> following at a shell prompt:
>
>     echo "echo 'ABC'" "|xsel --clipboard"
>
> Resulting in the expected output given the arguments you passed to that 
> function:
>
>     echo 'ABC'  |xsel --clipboard
>
> One solution is to use exec.Command() to run
>
>     sh -c "echo 'ABC' |xsel --clipboard"
>
> That, however, is difficult to do in the general case since getting the 
> quoting correct is a challenge.
>
>
> On Wed, Mar 25, 2020 at 11:30 AM <lgo...@gmail.com <javascript:>> wrote:
>
>> This simple command works correctly when submitted via the terminal, but 
>> the same command submitted to os.exec does not !!
>> .. and I can`t understand why...
>>
>> import ( "fmt"; "os"; "os/exec";  )
>>
>> func main() {
>>
>> cb := "ABCD"
>>
>> cmd := exec.Command ("echo", "echo "+ "'" +string(cb [0:len(cb)-1] ) 
>> +"'", " |xsel --clipboard" )
>> cmd.Stdout = os.Stdout
>> cmd.Stderr = os.Stderr
>> err := cmd.Run() ;    if err != nil { fmt.Printf("\ncmd.Run() error: %s 
>> \n", err) }
>>
>> }
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golan...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/f9b34d9d-985f-4cbf-9a92-d3d46d72cf55%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/f9b34d9d-985f-4cbf-9a92-d3d46d72cf55%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/348fcfba-b375-4ac7-9198-c48a5242d8f3%40googlegroups.com.

Reply via email to