Pause until external program exits with success?

  • Follow


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
0
Reply tuxedo (99) 8/11/2012 5:18:40 AM

Tuxedo <tuxedo@mailinator.com> 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
0
Reply jurgenex (445) 8/11/2012 6:45:10 AM


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

0
Reply tuxedo (99) 8/11/2012 8:51:56 PM

In article <k06gle$kf$1@news.albasani.net>,
Tuxedo  <tuxedo@mailinator.com> 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, tmcd@panix.com
0
Reply tmcd1 (189) 8/13/2012 3:44:04 PM

Tim McDaniel wrote:

> In article <k06gle$kf$1@news.albasani.net>,
> Tuxedo  <tuxedo@mailinator.com> 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
0
Reply tuxedo (99) 8/13/2012 8:32:02 PM

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.
>
> Tuxedo
>


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.
-- 
Cal
0
Reply cal819 (188) 8/14/2012 6:53:55 PM

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.
0
Reply glex_no-spam (67) 8/14/2012 7:35:14 PM

On 08/14/2012 01:35 PM, J. Gleixner wrote:
> 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.

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?
>
> BTW: ImageMagick (PerlMagick) can do this pretty easily.

OP already posted that, so your response added ZERO new data to this thread.
-- 
Cal
0
Reply cal819 (188) 8/14/2012 9:53:21 PM

Cal Dershowitz <cal@example.invalid> 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
0
Reply jurgenex (445) 8/14/2012 11:27:53 PM

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?'...

0
Reply glex_no-spam (67) 8/16/2012 3:07:45 PM

On 08/16/2012 09:07 AM, J. Gleixner wrote:
> 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.

Juergen, ich habe mich bei Dir zu entchuldigen.  Ich wollte nicht 
glauben, dass ich so wiederum machem musste.
>
>>>
>>> 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.

Woran?
>
>
> My point is, What does your post asking how to resize images have to do
> with 'Pause until external program exits with success?'...
>

I couldn't say.  Again, I apologize for not wanting to hear bad news and 
making it seem like it was your problem.
-- 
Cal
0
Reply cal819 (188) 8/20/2012 5:51:08 AM

10 Replies
43 Views

(page loaded in 0.214 seconds)


Reply: