Why won't exec work? - TCL

This is a discussion on Why won't exec work? - TCL ; Hi! I'm fairly new to tcl/tk so please don't be too hard on me. I'm writing a small program for myself to encode movies (memorizing all those options is a bit annoying). It basically has a simple GUI with a ...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16

Why won't exec work?

  1. Default Why won't exec work?

    Hi!
    I'm fairly new to tcl/tk so please don't be too hard on me.

    I'm writing a small program for myself to encode movies (memorizing all
    those options is a bit annoying). It basically has a simple GUI with a few
    buttons and some "entry"s to type in the bitrate and so on. Nothing really
    special.

    When I hit my OK-button it creates a normal shell command (which is stored
    in the variable "cmd") with mencoder or ffmpeg2theora.

    For example:
    > ffmpeg2theora --optimize -o /home/tim/videos/dsfargeg.ogg -v 10 -S 0 -a
    >10 -A 196 /home/tim/videos/sauce.avi

    or
    > mencoder -oac mp3lame -ovc lavc
    > -lavcopts vcodec=mpeg4:vqmin=1:vqmax=3:v4mv
    > /home/tim/videos/sauce.avi -o /home/tim/videos/dsfargeg.avi


    It's probably not necessary to know those programs to help me with my
    problem though. The problem is, that I try to open them with the
    exec-command which looks like this:
    > eval exec $cmd 2>/dev/null 1>/dev/null


    The problem I have now is that it just doesn't behave like a normal shell
    command. Videos encoded with mencoder don't have an index and ffmpeg2theora
    just doesn't start ("Child process exited abnormally" in an error window).
    If I just copy those commands and enter them into bash they work as
    expected. (I even did a "puts $cmd" before the exec to get the actual
    command to make sure that it is correct)

    Also, after mencoder finished, I get a VERY long error window. I thought I
    might get rid of that with moving everything to /dev/null but that doesn't
    work...

    What did I do wrong and how can I fix this?

    Thanks!

  2. Default Re: Why won't exec work?

    Dnia 22.02.2008 Tim Köhlmann <crono@crono.co.uk> napisa³/a:

    > The problem is, that I try to open them with the
    > exec-command which looks like this:
    >> eval exec $cmd 2>/dev/null 1>/dev/null

    >
    > The problem I have now is that it just doesn't behave like a normal shell
    > command. [..]
    > What did I do wrong and how can I fix this?


    I'm wondering, if small addition wouldn't the cure (8.5 only!), like this:

    eval exec {*}$cmd 2>/dev/null 1>/dev/null
    --
    ZB

  3. Default Re: Why won't exec work?

    ZB wrote:
    > Dnia 22.02.2008 Tim Köhlmann <crono@crono.co.uk> napisa³/a:
    >
    >> The problem is, that I try to open them with the
    >> exec-command which looks like this:
    >>> eval exec $cmd 2>/dev/null 1>/dev/null

    >> The problem I have now is that it just doesn't behave like a normal shell
    >> command. [..]
    >> What did I do wrong and how can I fix this?

    >
    > I'm wondering, if small addition wouldn't the cure (8.5 only!), like this:
    >
    > eval exec {*}$cmd 2>/dev/null 1>/dev/null


    No. The general rule of thumb is that you use {*} _in_place_of_ eval.
    Putting them together requires a *lot* of forethought.

    --
    Bryan Oakley
    http://www.tclscripting.com

  4. Default Re: Why won't exec work?

    At 2008-02-22 11:42AM, "Tim Köhlmann" wrote:
    > Hi!
    > I'm fairly new to tcl/tk so please don't be too hard on me.


    Welcome!
    > For example:
    > > ffmpeg2theora --optimize -o /home/tim/videos/dsfargeg.ogg -v 10 -S 0 -a
    > >10 -A 196 /home/tim/videos/sauce.avi

    > or
    > > mencoder -oac mp3lame -ovc lavc
    > > -lavcopts vcodec=mpeg4:vqmin=1:vqmax=3:v4mv
    > > /home/tim/videos/sauce.avi -o /home/tim/videos/dsfargeg.avi

    >
    > It's probably not necessary to know those programs to help me with my
    > problem though. The problem is, that I try to open them with the
    > exec-command which looks like this:
    > > eval exec $cmd 2>/dev/null 1>/dev/null


    Tcl's exec command has no "1>filename" argument. You might try

    tcl8.5: set output [exec {*}$cmd 2>@1]

    tcl8.4: set output [eval exec $cmd 2>@ stdout]

    See
    http://www.tcl.tk/man/tcl8.5/TclCmd/exec.htm
    http://www.tcl.tk/man/tcl8.4/TclCmd/exec.htm


    --
    Glenn Jackman
    "You can only be young once. But you can always be immature." -- Dave Barry

  5. Default Re: Why won't exec work?

    On Feb 22, 11:42 am, Tim Köhlmann <cr...@crono.co.uk> wrote:
    > after mencoder finished, I get a VERY long error window. I thought I
    > might get rid of that with moving everything to /dev/null but that doesn't
    > work...
    >


    Actually, you don't WANT to make the error window go away.. you want
    to always see the error and work on resolving it.

    I suspect that by making the error go away, the clues needed to figure
    out why the index is missing are tossed away.

    The problem with ffmepg... sounds like a situation where it is exiting
    with a non-zero return code. You need to read the man page for that
    tool to see why that would happen. If it is a "good thing", there is a
    tcl command called catch (read http://wiki.tcl.tk/catch for details)
    that can be used to capture tcl's attempt to tell you the program
    ended with a non-zero return code, at which time with some coding you
    can look at the return and determine whether you are getting an error
    condition or a success condition.

  6. Default Re: Why won't exec work?

    On Fri, 22 Feb 2008 10:08:39 -0800, Larry W. Virden wrote:

    > On Feb 22, 11:42 am, Tim Köhlmann <cr...@crono.co.uk> wrote:
    >> after mencoder finished, I get a VERY long error window. I thought I
    >> might get rid of that with moving everything to /dev/null but that doesn't
    >> work...
    >>

    >
    > Actually, you don't WANT to make the error window go away.. you want
    > to always see the error and work on resolving it.


    Sure, but it doesn't just show stderr, it also shows the complete stdout.
    And if you ever used mencoder then this is NOT very good... I tried to
    move the window itself up (under GNOME) so that I can see the buttons. I
    gave it up after one minute.

    > I suspect that by making the error go away, the clues needed to figure
    > out why the index is missing are tossed away.


    See above.

    > The problem with ffmepg... sounds like a situation where it is exiting
    > with a non-zero return code. You need to read the man page for that
    > tool to see why that would happen.


    But if I use the EXACT SAME command in bash it works flawlessly (exit-code 0).

    > If it is a "good thing", there is a
    > tcl command called catch (read http://wiki.tcl.tk/catch for details)
    > that can be used to capture tcl's attempt to tell you the program
    > ended with a non-zero return code, at which time with some coding you
    > can look at the return and determine whether you are getting an error
    > condition or a success condition.


  7. Default Re: Why won't exec work?

    On Fri, 22 Feb 2008 17:44:26 +0000, Glenn Jackman wrote:

    > At 2008-02-22 11:42AM, "Tim Köhlmann" wrote:
    >> Hi!
    >> I'm fairly new to tcl/tk so please don't be too hard on me.

    >
    > Welcome!
    >> For example:
    >> > ffmpeg2theora --optimize -o /home/tim/videos/dsfargeg.ogg -v 10 -S 0 -a
    >> >10 -A 196 /home/tim/videos/sauce.avi

    >> or
    >> > mencoder -oac mp3lame -ovc lavc
    >> > -lavcopts vcodec=mpeg4:vqmin=1:vqmax=3:v4mv
    >> > /home/tim/videos/sauce.avi -o /home/tim/videos/dsfargeg.avi

    >>
    >> It's probably not necessary to know those programs to help me with my
    >> problem though. The problem is, that I try to open them with the
    >> exec-command which looks like this:
    >> > eval exec $cmd 2>/dev/null 1>/dev/null

    >
    > Tcl's exec command has no "1>filename" argument. You might try
    >
    > tcl8.5: set output [exec {*}$cmd 2>@1]
    >
    > tcl8.4: set output [eval exec $cmd 2>@ stdout]
    >
    > See
    > http://www.tcl.tk/man/tcl8.5/TclCmd/exec.htm
    > http://www.tcl.tk/man/tcl8.4/TclCmd/exec.htm
    >
    >


    I use 8.4 and that worked! Even ffmpeg works now.
    The only question left is: Why?

    Thank you very much!
    Tim

  8. Default Re: Why won't exec work?

    On Fri, 22 Feb 2008 10:08:39 -0800, Larry W. Virden wrote:

    > On Feb 22, 11:42 am, Tim Köhlmann <cr...@crono.co.uk> wrote:
    >> after mencoder finished, I get a VERY long error window. I thought I
    >> might get rid of that with moving everything to /dev/null but that doesn't
    >> work...
    >>

    >
    > Actually, you don't WANT to make the error window go away.. you want
    > to always see the error and work on resolving it.


    Normally, yes. But the error window doesn't give me stderr, it shows the
    complete stdout. And that's DEFIANTELY not what I want.
    Any hints how to do that are greatly appreciated. Especailly if I can
    somehow store stderr and stdout in different variables so I can put in a
    window which asks if the user wants to see them.

    > I suspect that by making the error go away, the clues needed to figure
    > out why the index is missing are tossed away.


    See my other reply to Glenn - same with ffmpeg.

    > The problem with ffmepg... sounds like a situation where it is exiting
    > with a non-zero return code. You need to read the man page for that
    > tool to see why that would happen. If it is a "good thing", there is a
    > tcl command called catch (read http://wiki.tcl.tk/catch for details)
    > that can be used to capture tcl's attempt to tell you the program
    > ended with a non-zero return code, at which time with some coding you
    > can look at the return and determine whether you are getting an error
    > condition or a success condition.


  9. Default Re: Why won't exec work?

    Anonymous /b/tard wrote:
    > On Fri, 22 Feb 2008 10:08:39 -0800, Larry W. Virden wrote:
    >
    >> On Feb 22, 11:42 am, Tim Köhlmann <cr...@crono.co.uk> wrote:
    >>> after mencoder finished, I get a VERY long error window. I thought I
    >>> might get rid of that with moving everything to /dev/null but that doesn't
    >>> work...
    >>>

    >> Actually, you don't WANT to make the error window go away.. you want
    >> to always see the error and work on resolving it.

    >
    > Sure, but it doesn't just show stderr, it also shows the complete stdout.
    > And if you ever used mencoder then this is NOT very good... I tried to
    > move the window itself up (under GNOME) so that I can see the buttons. I
    > gave it up after one minute.


    try putting the output into a text widget with a scrollbar.

    you can also exchange the exec with a call to open "|$cmd" (see man pages or wiki)
    and then you can show the output as it is running instead of all at the end.

    Bruce

  10. Default Re: Why won't exec work?

    On Fri, 22 Feb 2008 14:04:39 -0600, Bruce Hartweg wrote:

    > Anonymous /b/tard wrote:
    >> On Fri, 22 Feb 2008 10:08:39 -0800, Larry W. Virden wrote:
    >>
    >>> On Feb 22, 11:42 am, Tim Köhlmann <cr...@crono.co.uk> wrote:
    >>>> after mencoder finished, I get a VERY long error window. I thought I
    >>>> might get rid of that with moving everything to /dev/null but that doesn't
    >>>> work...
    >>>>
    >>> Actually, you don't WANT to make the error window go away.. you want
    >>> to always see the error and work on resolving it.

    >>
    >> Sure, but it doesn't just show stderr, it also shows the complete stdout.
    >> And if you ever used mencoder then this is NOT very good... I tried to
    >> move the window itself up (under GNOME) so that I can see the buttons. I
    >> gave it up after one minute.

    >
    > try putting the output into a text widget with a scrollbar.


    The problem is: How?
    I don't open ANY window manually. When the command is done it pops up
    automatically. Here's a screenshot for you:
    http://img182.imageshack.us/img182/5...ationsfqv2.png


    > you can also exchange the exec with a call to open "|$cmd" (see man pages or wiki)
    > and then you can show the output as it is running instead of all at the
    > end.


    I don't really want to see that during conversion. It'd be OK if I can get
    stdout and stderr into variables so I can make a dialoge that asks me if I
    want to see it...

    >
    > Bruce


+ Reply to Thread
Page 1 of 2 1 2 LastLast