comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Calling IDL from Perl
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Calling IDL from Perl [message #26956] Wed, 03 October 2001 13:43
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
You are trying to do interprocess communications the poor man's way,
and you are getting poor man's results. :-)

Here are a couple of suggestions.

One possibility is that the programs run in the order you expect, but
their outputs are flushed to the screen in the wrong order. Both
processes will get access to the same output stream, but the *order*
that they get it is not usually well defined. The solution is for you
to capture the output of IDL within perl, and then print them from
within perl.

Another thing to try is to send all of your commands to IDL at once.
Ie, build up a list of commands, including "exit", and dump those out
to the IDL session when you open it.

Finally, you could send all those commands to a "file.pro" and then
start IDL by calling on the command line "idl file.pro".

Do these help?
Craig


gary.hodgesREMOVE@cires.colorado.edu writes:
> OK, I have distilled my problem down to the simplest example I can. My
> problem is that the Perl script finishes before the IDL script is executed.
> I have tried sleep commands, but the results are the same. What can I do to
> get the IDL script to execute before the Perl script prints the contents of
> @ary? Below are the two scripts and the output.
>
> Cheers,
> Gary
>
>
> #!/usr/bin/perl
> open(IDL, "|/usr/local/bin/idl");
> print IDL ".Compile loop \n";
> print IDL "loop \n";
> @ary=(5,6,7,8);
> for (@ary) {
> print "$_\n";
> }
> ----------------------------------
> PRO LOOP
> FOR j=1,4 DO BEGIN
> Print, j
> ENDFOR
> END
> ==================================
> The output when I run the Perl code is:
>
> phoenix> perl loop.pl
> 5
> 6
> 7
> 8
> phoenix> IDL Version 5.4 (sunos sparc). (c) 2000, Research Systems, Inc.
> Installation number: 100780-40.
> Licensed for use by: OAR/ARL:Chris Cornwall:SUN100
>
> % Compiled module: LOOP.
> 1
> 2
> 3
> 4
>
>

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Calling IDL from Perl [message #26963 is a reply to message #26956] Wed, 03 October 2001 12:24 Go to previous message
gary.hodgesREMOVE is currently offline  gary.hodgesREMOVE
Messages: 9
Registered: October 2001
Junior Member
JD Smith <jdsmith@astro.cornell.edu> wrote:
: gary.hodgesREMOVE@cires.colorado.edu wrote:
:>
:> OK, I have distilled my problem down to the simplest example I can. My
:> problem is that the Perl script finishes before the IDL script is executed.
:> I have tried sleep commands, but the results are the same. What can I do to
:> get the IDL script to execute before the Perl script prints the contents of
:> @ary? Below are the two scripts and the output.

: close IDL; #THIS ONE CRITICAL

: Since you weren't closing the filehandle, the IDL input was not being
: flushed, until after the program exited (at which point it was forced
: close).

Thank you so much. It seems so obvious now...

Cheers,
Gary
Re: Calling IDL from Perl [message #26965 is a reply to message #26963] Wed, 03 October 2001 12:20 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
gary.hodgesREMOVE@cires.colorado.edu wrote:
>
> OK, I have distilled my problem down to the simplest example I can. My
> problem is that the Perl script finishes before the IDL script is executed.
> I have tried sleep commands, but the results are the same. What can I do to
> get the IDL script to execute before the Perl script prints the contents of
> @ary? Below are the two scripts and the output.

Not that this is a perl list, but try:

#!/usr/bin/perl
open(IDL, "|/usr/local/bin/idl");
print IDL ".Compile loop \n";
print IDL "loop \n";
close IDL; #THIS ONE CRITICAL
@ary=(5,6,7,8);
for (@ary) {
print "$_\n";
}

Since you weren't closing the filehandle, the IDL input was not being
flushed, until after the program exited (at which point it was forced
close).

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: right-justifying draw widgets?
Next Topic: Re: Is there a line widget

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:05:23 PDT 2025

Total time taken to generate the page: 0.00597 seconds