exec.Command with options list

1,037 views
Skip to first unread message

bdentremont

unread,
Aug 29, 2013, 12:04:49 PM8/29/13
to golan...@googlegroups.com
I'm trying to combine some plots in PNG into a movie on Ubuntu.  I would like this to happen automatically after running my Go program.  If I run from the bash shell,

cd /tmp/2013-08-29_16.54.51.432786
mencoder "mf://*.png" -o movie.avi -ovc x264

I get what I want.  However, when I attempt to call the shell command in Go, I get the following error:

"MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team

Exiting... (No output file specified, please see the -o option.)"


Both the commented "ls" commands in the following code work properly and the output verifies that I'm in the right directory.  Can someone point me in the direction of what I'm missing?

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    cmd := exec.Command(`mencoder`, `mf://*.png -o movie.avi -ovc x264`)
    //cmd := exec.Command(`ls`, `-la`)
    //cmd := exec.Command(`ls`, `-l`, `-a`)
    cmd.Dir = "/tmp/2013-08-29_16.54.51.432786"
    out, _ := cmd.CombinedOutput()
    fmt.Println(string(out))
}

Rémy Oudompheng

unread,
Aug 29, 2013, 12:20:08 PM8/29/13
to bdentremont, golang-nuts
2013/8/29 bdentremont <bdent...@gmail.com>:
> I'm trying to combine some plots in PNG into a movie on Ubuntu. I would
> like this to happen automatically after running my Go program. If I run
> from the bash shell,
>
> cd /tmp/2013-08-29_16.54.51.432786
> mencoder "mf://*.png" -o movie.avi -ovc x264
>
> I get what I want. However, when I attempt to call the shell command in Go,
> I get the following error:
>
> "MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team
>
> Exiting... (No output file specified, please see the -o option.)"
>
>
> Both the commented "ls" commands in the following code work properly and the
> output verifies that I'm in the right directory. Can someone point me in
> the direction of what I'm missing?
>
> package main
>
> import (
> "fmt"
> "os/exec"
> )
>
> func main() {
> cmd := exec.Command(`mencoder`, `mf://*.png -o movie.avi -ovc x264`)

This command calls mencoder on a file named "mf://*.png -o movie.avi
-ovc x264". Do you have a file named like that?

Rémy.

bdentremont

unread,
Aug 29, 2013, 1:32:40 PM8/29/13
to golan...@googlegroups.com, bdentremont

This command calls mencoder on a file named "mf://*.png -o movie.avi
-ovc x264". Do you have a file named like that?

Rémy.

Rémy:
Thank you for your advice.  I indeed do not have a file by that name.  However, I also do not have one by the name "-la" nor "hello" yet "exec.Command(`ls`, `-la`)" and the example given in the "os/exec" documentation "exec.Command("echo", "hello")" both work fine.  Is there a reason that one would get interpreted as a file path and the other passed as string?  This may be obvious to you via your experience in other languages, but I'm a novice programmer trying to learn.
Brian

Sebastien Binet

unread,
Aug 29, 2013, 1:57:16 PM8/29/13
to bdentremont, golang-nuts

sent from my droid


On Aug 29, 2013 6:18 PM, "bdentremont" <bdent...@gmail.com> wrote:
>
> I'm trying to combine some plots in PNG into a movie on Ubuntu.  I would like this to happen automatically after running my Go program.  If I run from the bash shell,
>
> cd /tmp/2013-08-29_16.54.51.432786
> mencoder "mf://*.png" -o movie.avi -ovc x264
>
> I get what I want.  However, when I attempt to call the shell command in Go, I get the following error:
>
> "MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team
>
> Exiting... (No output file specified, please see the -o option.)"
>
>
> Both the commented "ls" commands in the following code work properly and the output verifies that I'm in the right directory.  Can someone point me in the direction of what I'm missing?
>
> package main
>
> import (
>     "fmt"
>     "os/exec"
> )
>
> func main() {
>     cmd := exec.Command(`mencoder`, `mf://*.png -o movie.avi -ovc x264`)

This should read:
cmd := exec.Command(`mencoder`, `mf://*.png', '-o', 'movie.avi', 'x264`)

With double quotes all along.

-s

>     //cmd := exec.Command(`ls`, `-la`)
>     //cmd := exec.Command(`ls`, `-l`, `-a`)
>     cmd.Dir = "/tmp/2013-08-29_16.54.51.432786"
>     out, _ := cmd.CombinedOutput()
>     fmt.Println(string(out))
> }
>

> --
> 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...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

bdentremont

unread,
Aug 29, 2013, 2:25:48 PM8/29/13
to golan...@googlegroups.com, bdentremont

Sebastien:
Thank you, but I get exactly the same error with that as well.
Brian


package main

import (
    "fmt"
    "os/exec"
)

func main() {
    cmd := exec.Command(`mencoder`, `mf://*.png', '-o', 'movie.avi', 'x264`)
    out, _ := cmd.CombinedOutput()
    fmt.Println(string(out))
}

MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team

Exiting... (No output file specified, please see the -o option.)



Brad Fitzpatrick

unread,
Aug 29, 2013, 2:27:22 PM8/29/13
to bdentremont, golang-nuts
You're not even looking at the error.  You're ignoring it with _


--

Brad Fitzpatrick

unread,
Aug 29, 2013, 2:29:58 PM8/29/13
to bdentremont, golang-nuts
What is with your mix of backticks and single quotes?

You're passing one argument (`mf://*.png', '-o', 'movie.avi', 'x264`) to mencoder.



On Thu, Aug 29, 2013 at 11:25 AM, bdentremont <bdent...@gmail.com> wrote:
--

bdentremont

unread,
Aug 29, 2013, 2:52:52 PM8/29/13
to golan...@googlegroups.com, bdentremont
Brad:
I'm aware of that.  My original attempt at this paniced on error.  Yet, it seemed that the shell output, not the exit status characterized my problem.

You are, of course, entirely right about the quote issue.  I'd cut and pasted a previous reply and didn't see that.  As things currently stand:


package main

import (
    "fmt"
    "os/exec"
)

func main() {
    cmd := exec.Command(`mencoder`, `"mf://*.png"`, `-o`, `movie.avi`, `x264`)
    cmd.Dir = "/tmp/2013-08-29_16.54.51.432786"

    out, err := cmd.CombinedOutput()
    fmt.Println(string(out))
    if err != nil {
        panic(err)

    }
}

MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team

No stream found to handle url "mf://*.png"

Cannot open file/device.


Exiting...


panic: exit status 1


goroutine 1 [running]:

main.main()

/home/brian/go/src/bdentremont/tmp/main.go:15 +0x186


goroutine 2 [syscall]:

created by runtime.main

/build/buildd/golang-1/src/pkg/runtime/proc.c:221

Error: process exited with code 2.

Brad Fitzpatrick

unread,
Aug 29, 2013, 2:56:24 PM8/29/13
to bdentremont, golang-nuts
Every version of your code has new random quotes.

Here:

`"mf://*.png"`

You're passing double quotes to mencoder.

Pick one.  Use either raw quotes (``) or double-quotes ("") but not both.  With raw quotes, the Go string has double quotes in it and you're passing them down to mencoder.

Your basic confusion is that you don't understand that your shell is splitting up your command-line into arguments for you.


bdentremont

unread,
Aug 29, 2013, 3:09:56 PM8/29/13
to golan...@googlegroups.com, bdentremont
Brad:
Thank you.  The following works perfectly.  Your comment "Your basic confusion is that you don't understand that your shell is splitting up your command-line into arguments for you." clarifies things greatly.  I appreciate your patience.

Brian

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    cmd := exec.Command(`mencoder`, `mf://*.png`, `-o`, `movie.avi`, `-ovc`, `x264`)
Reply all
Reply to author
Forward
0 new messages