Re: Calling IDL from Perl [message #26956] |
Wed, 03 October 2001 13:43 |
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  |
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  |
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
|
|
|