Pause until external program exits with success?

Discussion in 'Perl Misc' started by Tuxedo, Aug 11, 2012.

  1. Tuxedo

    Tuxedo Guest

    In running an external process I would like to continue (or terminate) a
    script depending on the output of the external process.

    For example, if the process is to scale a very large image with
    ImageMagick's convert, how can the script be made to continue after the
    completion of the external system process, e.g. once ImageMagick's Fatal
    Error exit code has returned 0:

    system "convert -quality 80 -resize 500x600 giant.jpg small.jpg";

    more stuff....

    What are good ways to proceed with more stuff if/when the system command
    has completed?

    Tuxedo
    Tuxedo, Aug 11, 2012
    #1
    1. Advertising

  2. Tuxedo <> wrote:
    >In running an external process I would like to continue (or terminate) a
    >script depending on the output of the external process.
    >
    >For example, if the process is to scale a very large image with
    >ImageMagick's convert, how can the script be made to continue after the
    >completion of the external system process, e.g. once ImageMagick's Fatal
    >Error exit code has returned 0:
    >
    >system "convert -quality 80 -resize 500x600 giant.jpg small.jpg";


    'perldoc -f system' describes two different ways for how to check the
    return value of an external process. Did you try those? Did neither
    work?

    >more stuff....
    >
    >What are good ways to proceed with more stuff if/when the system command
    >has completed?


    What you are asking for is system()'s standard behaviour. What behaviour
    are you observing instead?

    jue
    Jürgen Exner, Aug 11, 2012
    #2
    1. Advertising

  3. Tuxedo

    Tuxedo Guest

    Jürgen Exner wrote:

    [...]

    > 'perldoc -f system' describes two different ways for how to check the
    > return value of an external process. Did you try those? Did neither
    > work?


    No I didn't, thanks for the pointer.

    > >What are good ways to proceed with more stuff if/when the system command
    > >has completed?

    >
    > What you are asking for is system()'s standard behaviour. What behaviour
    > are you observing instead?


    Not knowing what to look for I did not test anything yet. I will look into
    'system' and also System::Command. I'm not sure which may be a better way.

    Thanks for the tips!
    Tuxedo
    Tuxedo, Aug 11, 2012
    #3
  4. Tuxedo

    Tim McDaniel Guest

    In article <k06gle$kf$>,
    Tuxedo <> wrote:
    >Not knowing what to look for I did not test anything yet. I will look into
    >'system' and also System::Command. I'm not sure which may be a better way.


    I have done quite well with using just system(). It has the great
    advantage of having been built in to Perl since Perl 4 and I presume
    from about day 1 -- I run scripts on a number of systems that I don't
    control and that have revisions anywhere from 5.8 to 5.14.

    In most cases, I've needed to check only zero versus non-zero. In the
    few cases where I've wanted to know the exact code, I used the code
    provided in "perldoc -f system" to break out the exit code, signal,
    and/or coredump.

    The other concern is how to deal with shell processing. I want the
    shell involved if I'm doing something like
    system("server_proc < '$control_file' > '$log_out' 2>&1")
    so I use the one-argument form. But in many cases I have my own
    filenames and stuff that I don't want the shell to interpret. In that
    case, I do the >1 argument form, as detailed in the system doc.

    If you need to provide input programmatically or need to process the
    output, then you have to get all complicated with open with pipes
    instead of system.

    --
    Tim McDaniel,
    Tim McDaniel, Aug 13, 2012
    #4
  5. Tuxedo

    Tuxedo Guest

    Tim McDaniel wrote:

    > In article <k06gle$kf$>,
    > Tuxedo <> wrote:
    > >Not knowing what to look for I did not test anything yet. I will look
    > >into 'system' and also System::Command. I'm not sure which may be a
    > >better way.

    >
    > I have done quite well with using just system(). It has the great
    > advantage of having been built in to Perl since Perl 4 and I presume
    > from about day 1 -- I run scripts on a number of systems that I don't
    > control and that have revisions anywhere from 5.8 to 5.14.
    >
    > In most cases, I've needed to check only zero versus non-zero. In the
    > few cases where I've wanted to know the exact code, I used the code
    > provided in "perldoc -f system" to break out the exit code, signal,
    > and/or coredump.
    >
    > The other concern is how to deal with shell processing. I want the
    > shell involved if I'm doing something like
    > system("server_proc < '$control_file' > '$log_out' 2>&1")
    > so I use the one-argument form. But in many cases I have my own
    > filenames and stuff that I don't want the shell to interpret. In that
    > case, I do the >1 argument form, as detailed in the system doc.
    >
    > If you need to provide input programmatically or need to process the
    > output, then you have to get all complicated with open with pipes
    > instead of system.
    >


    Thanks for the above detailed info. It will come handy for something. In
    this case, I realised following a previous response that system waits with
    proceeding onto the next block upon completing the system call, which was
    all I needed the script to do after all.

    Tuxedo
    Tuxedo, Aug 13, 2012
    #5
  6. Tuxedo

    J. Gleixner Guest

    On 08/14/12 13:53, Cal Dershowitz wrote:
    [...]
    >
    > I'd love to see your source for this. The images I have coming off my
    > camera are huge for html, and I'd like to develop a toolchain to make
    > them all no bigger than 800-1000 pixels in its largest dimension.


    Instead of hijacking a previous post, which doesn't have anything to
    do with your particular question, it would be better if you would
    post a new one with a pertinent subject and question.

    BTW: ImageMagick (PerlMagick) can do this pretty easily.
    J. Gleixner, Aug 14, 2012
    #6
  7. Cal Dershowitz <> wrote:
    >On 08/13/2012 02:32 PM, Tuxedo wrote:
    >
    >> Thanks for the above detailed info. It will come handy for something. In
    >> this case, I realised following a previous response that system waits with
    >> proceeding onto the next block upon completing the system call, which was
    >> all I needed the script to do after all.

    >
    >I'd love to see your source for this.


    While it's not my source code, calling system() is really simple. See
    perldoc -f system for several examples, including capturing the return
    code or calling system with a single parameter or a list of parameters.

    >The images I have coming off my
    >camera are huge for html, and I'd like to develop a toolchain to make
    >them all no bigger than 800-1000 pixels in its largest dimension.


    What images? The OP was asking about system(). That has nothing to do
    with images.

    jue
    Jürgen Exner, Aug 15, 2012
    #7
  8. Tuxedo

    J. Gleixner Guest

    On 08/14/12 16:53, Cal Dershowitz wrote:
    > On 08/14/2012 01:35 PM, J. Gleixner wrote:
    >> On 08/14/12 13:53, Cal Dershowitz wrote:
    >> [...]
    >>>

    >> Instead of hijacking a previous post, which doesn't have anything to
    >> do with your particular question, it would be better if you would
    >> post a new one with a pertinent subject and question.

    >
    > How is asking for the OP's source a "hijack." I don't want to start a
    > new thread with this, because it's not the most important thing I'm
    > working on now, and who died to leave you as Abigail van Buren to
    > c.l.p.misc?


    Whatever.. I'm trying to help you, before everyone starts filtering all
    of your posts because you continue to do this.

    >>
    >> BTW: ImageMagick (PerlMagick) can do this pretty easily.

    >
    > OP already posted that, so your response added ZERO new data to this
    > thread.


    And yours continues to lower your relevance.


    My point is, What does your post asking how to resize images have to do
    with 'Pause until external program exits with success?'...
    J. Gleixner, Aug 16, 2012
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ning
    Replies:
    4
    Views:
    689
    Dan Pop
    Sep 26, 2003
  2. Ian Wilson
    Replies:
    4
    Views:
    633
    Ian Wilson
    Jan 24, 2007
  3. Replies:
    30
    Views:
    1,462
    niraj
    Jul 3, 2011
  4. James Coglan

    Detect when a Ruby program exits

    James Coglan, Jan 9, 2009, in forum: Ruby
    Replies:
    2
    Views:
    115
    James Coglan
    Jan 9, 2009
  5. Lance
    Replies:
    3
    Views:
    128
    Matt Garrish
    Sep 29, 2006
Loading...

Share This Page