Pause until external program exits with success?

T

Tuxedo

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
 
J

Jürgen Exner

Tuxedo said:
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
 
T

Tuxedo

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 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
 
T

Tim McDaniel

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

Tuxedo

Tim said:
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
 
J

J. Gleixner

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

Jürgen Exner

Cal Dershowitz said:
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

J. Gleixner

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top