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

Home » Public Forums » archive » Re: Need help with basic spawn command
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: Need help with basic spawn command [message #54059] Thu, 17 May 2007 08:32 Go to next message
ryanselk is currently offline  ryanselk
Messages: 16
Registered: May 2007
Junior Member
On May 17, 2:45 am, Yi <yi.se...@gmail.com> wrote:
> IDL's spawn procedure can't get the return value from C program.
> Of course, you can get the result using second argument like this :
>
> IDL> spawn, 'basic', result
>
> In this case, the result variable is not the return value of main
> function(C Program)
> but the output text result of the 'basic' command in Shell(Unix) or
> Command Prompt(MS Windows)
>
> The 'result' variable is string array, so it can catch multi lines
> text output.
>
> Anyway, if you want to use spawn procedure, the C program should be
> modified.
>
> I expect that you can get result if you insert,
>
> printf("%d", n);
>
> into your C code.
>
> On 5월17일, 오전7시34분, ryans...@gmail.com wrote:
>
>> Im running IDL on XP.
>
>> I have this basic C code:
>
>> #include <stdlib.h>
>
>> int main()
>> {
>
>> int n=5;
>> n=n*2;
>> return n;}
>
>> //This file is basic.c
>
>>> From IDL, I just want to call this program and return n.
>
>> In IDL, I can write:
>
>> SPAWN, 'basic' ; this of course runs the
>> basic.c program.
>
>> But this doesnt return anythingof course.. ive tried to add another
>> variable after this line such as:
>> SPAWN, 'basic', variable
>
>> But windows doesnt like any of this...
>
>> Can anyone help me with this basic application? With spawn in the past
>> ive gotten it to do calculations on a variable and return them, but
>> with no input, im unsure how to get the output.
>
>> Thanks for any help! Ive also boughten the 'from c->dlm->idl' book but
>> it wont be in for a few days.


Thank you so much, I understand now! Your right that it works when
adding a printf to the code with the result on the spawn.

I was under the impression that this would not work on windows, only
unix, not sure why, but it does.
Re: Need help with basic spawn command [message #54060 is a reply to message #54059] Thu, 17 May 2007 08:12 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
ryanselk@gmail.com wrote:
> Im running IDL on XP.
>
>
>
> I have this basic C code:
>
>
> #include <stdlib.h>
>
> int main()
> {
>
> int n=5;
> n=n*2;
> return n;
> }
> //This file is basic.c
>
>
>
>> From IDL, I just want to call this program and return n.
>
>
>
> In IDL, I can write:
>
> SPAWN, 'basic' ; this of course runs the
> basic.c program.
>
>
> But this doesnt return anythingof course.. ive tried to add another
> variable after this line such as:
> SPAWN, 'basic', variable

'variable' is supposed to contain whatever output your program
produces - in C terms, it contains whatever was written to stdout.
Your program doesn't write anything to stdout, so variable won't
contain any information. If you want to retrieve the exit status, what
you want is:

SPAWN, 'basic', EXIT_STATUS=variable
Re: Need help with basic spawn command [message #54062 is a reply to message #54060] Thu, 17 May 2007 07:02 Go to previous messageGo to next message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
On May 16, 5:34 pm, ryans...@gmail.com wrote:
> Im running IDL on XP.
>
> I have this basic C code:
>
> #include <stdlib.h>
>
> int main()
> {
>
> int n=5;
> n=n*2;
> return n;}
>
> //This file is basic.c
>
>> From IDL, I just want to call this program and return n.
>
> In IDL, I can write:
>
> SPAWN, 'basic' ; this of course runs the
> basic.c program.
>
> But this doesnt return anythingof course.. ive tried to add another
> variable after this line such as:
> SPAWN, 'basic', variable
>
> But windows doesnt like any of this...
>
> Can anyone help me with this basic application? With spawn in the past
> ive gotten it to do calculations on a variable and return them, but
> with no input, im unsure how to get the output.
>
> Thanks for any help! Ive also boughten the 'from c->dlm->idl' book but
> it wont be in for a few days.

I think your on the right track by "boughtening" the book, but a quick
and dirty answer: Have you c-program write to stdout, then use spawn.

Good luck!
Re: Need help with basic spawn command [message #54064 is a reply to message #54062] Thu, 17 May 2007 05:46 Go to previous messageGo to next message
yp is currently offline  yp
Messages: 42
Registered: February 2005
Member
On May 16, 11:34 pm, ryans...@gmail.com wrote:
> Im running IDL on XP.
>
> I have this basic C code:
>
> #include <stdlib.h>
>
> int main()
> {
>
> int n=5;
> n=n*2;
> return n;}
>
> //This file is basic.c
>
>> From IDL, I just want to call this program and return n.
>
> In IDL, I can write:
>
> SPAWN, 'basic' ; this of course runs the
> basic.c program.
>
> But this doesnt return anythingof course.. ive tried to add another
> variable after this line such as:
> SPAWN, 'basic', variable
>
> But windows doesnt like any of this...
>
> Can anyone help me with this basic application? With spawn in the past
> ive gotten it to do calculations on a variable and return them, but
> with no input, im unsure how to get the output.
>
> Thanks for any help! Ive also boughten the 'from c->dlm->idl' book but
> it wont be in for a few days.

In this case the output (10) is written to the console (i.e, your
windows command prompt shell...) add a line in your C-code
system(pause); //I am not sure which compiler you are using

-y
Re: Need help with basic spawn command [message #54066 is a reply to message #54064] Thu, 17 May 2007 04:14 Go to previous messageGo to next message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
Note that the return value can be obtained (at least under unix) with
the exit_status keyword to spawn.

IDL> spawn, 'basic', exit_status=a
IDL> print,a
10

however, it's far more useful to use the printf in your program as Yi
suggested to return data back. The exit status is typically used to
return whether or not a command executed correctly or not.

Probably best to ignore this message unless you're really sure that you
want the return value from the program rather than just its output.

Thanks,

Allan

Yi wrote:
> IDL's spawn procedure can't get the return value from C program.
> Of course, you can get the result using second argument like this :
>
> IDL> spawn, 'basic', result
>
> In this case, the result variable is not the return value of main
> function(C Program)
> but the output text result of the 'basic' command in Shell(Unix) or
> Command Prompt(MS Windows)
>
> The 'result' variable is string array, so it can catch multi lines
> text output.
>
> Anyway, if you want to use spawn procedure, the C program should be
> modified.
>
> I expect that you can get result if you insert,
>
> printf("%d", n);
>
> into your C code.
>
>
> On 5占쏙옙17占쏙옙, 占쏙옙占쏙옙7占쏙옙34占쏙옙, ryans...@gmail.com wrote:
>
>> Im running IDL on XP.
>>
>> I have this basic C code:
>>
>> #include <stdlib.h>
>>
>> int main()
>> {
>>
>> int n=5;
>> n=n*2;
>> return n;}
>>
>> //This file is basic.c
>>
>>> From IDL, I just want to call this program and return n.
>>
>> In IDL, I can write:
>>
>> SPAWN, 'basic' ; this of course runs the
>> basic.c program.
>>
>> But this doesnt return anythingof course.. ive tried to add another
>> variable after this line such as:
>> SPAWN, 'basic', variable
>>
>> But windows doesnt like any of this...
>>
>> Can anyone help me with this basic application? With spawn in the past
>> ive gotten it to do calculations on a variable and return them, but
>> with no input, im unsure how to get the output.
>>
>> Thanks for any help! Ive also boughten the 'from c->dlm->idl' book but
>> it wont be in for a few days.
>
>
>
Re: Need help with basic spawn command [message #54069 is a reply to message #54066] Thu, 17 May 2007 01:45 Go to previous messageGo to next message
yi.selab is currently offline  yi.selab
Messages: 9
Registered: July 2006
Junior Member
IDL's spawn procedure can't get the return value from C program.
Of course, you can get the result using second argument like this :

IDL> spawn, 'basic', result

In this case, the result variable is not the return value of main
function(C Program)
but the output text result of the 'basic' command in Shell(Unix) or
Command Prompt(MS Windows)

The 'result' variable is string array, so it can catch multi lines
text output.

Anyway, if you want to use spawn procedure, the C program should be
modified.

I expect that you can get result if you insert,

printf("%d", n);

into your C code.


On 5월17일, 오전7시34분, ryans...@gmail.com wrote:
> Im running IDL on XP.
>
> I have this basic C code:
>
> #include <stdlib.h>
>
> int main()
> {
>
> int n=5;
> n=n*2;
> return n;}
>
> //This file is basic.c
>
>> From IDL, I just want to call this program and return n.
>
> In IDL, I can write:
>
> SPAWN, 'basic' ; this of course runs the
> basic.c program.
>
> But this doesnt return anythingof course.. ive tried to add another
> variable after this line such as:
> SPAWN, 'basic', variable
>
> But windows doesnt like any of this...
>
> Can anyone help me with this basic application? With spawn in the past
> ive gotten it to do calculations on a variable and return them, but
> with no input, im unsure how to get the output.
>
> Thanks for any help! Ive also boughten the 'from c->dlm->idl' book but
> it wont be in for a few days.
Re: Need help with basic spawn command [message #54102 is a reply to message #54059] Tue, 22 May 2007 05:55 Go to previous message
Trae is currently offline  Trae
Messages: 23
Registered: May 2007
Junior Member
Sorry for jumpiing on this thread late.

Why don't you use a combination of make_dll and call_external to have
IDL call your C code? I do a lot of number crunching in IDL and write
C codes to do much of the tedious but large jobs. These are the
procedures I use to get C an IDL to talk to each other.

The learning curve on these procedures is not bad and I've had great
success with them. It also sounds easier than what you are trying to
do with printf and if you are worried about time, nothing takes longer
than reading files. Call_external allows you to pass variables.

Cheers,
-Trae

Cheers,

On May 17, 9:32 am, ryans...@gmail.com wrote:
> On May 17, 2:45 am, Yi <yi.se...@gmail.com> wrote:
>
>
>
>> IDL's spawn procedure can't get the return value from C program.
>> Of course, you can get the result using second argument like this :
>
>> IDL> spawn, 'basic', result
>
>> In this case, the result variable is not the return value of main
>> function(C Program)
>> but the output text result of the 'basic' command in Shell(Unix) or
>> Command Prompt(MS Windows)
>
>> The 'result' variable is string array, so it can catch multi lines
>> text output.
>
>> Anyway, if you want to use spawn procedure, the C program should be
>> modified.
>
>> I expect that you can get result if you insert,
>
>> printf("%d", n);
>
>> into your C code.
>
>> On 5월17일, 오전7시34분, ryans...@gmail.com wrote:
>
>>> Im running IDL on XP.
>
>>> I have this basic C code:
>
>>> #include <stdlib.h>
>
>>> int main()
>>> {
>
>>>       int n=5;
>>>       n=n*2;
>>>       return n;}
>
>>> //This file is basic.c
>
>>>> From IDL, I just want to call this program and return n.
>
>>> In IDL, I can write:
>
>>> SPAWN, 'basic'                           ; this of course runs the
>>> basic.c program.
>
>>> But this doesnt return anythingof course.. ive tried to add another
>>> variable after this line such as:
>>> SPAWN, 'basic', variable
>
>>> But windows doesnt like any of this...
>
>>> Can anyone help me with this basic application? With spawn in the past
>>> ive gotten it to do calculations on a variable and return them, but
>>> with no input, im unsure how to get the output.
>
>>> Thanks for any help! Ive also boughten the 'from c->dlm->idl' book but
>>> it wont be in for a few days.
>
> Thank you so much, I understand now! Your right that it works when
> adding a printf to the code with the result on the spawn.
>
> I was under the impression that this would not work on windows, only
> unix, not sure why, but it does.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: write a root group to HDF5 file
Next Topic: 2D interpolation with sparse data

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

Current Time: Wed Oct 08 13:51:38 PDT 2025

Total time taken to generate the page: 0.01119 seconds