SPAWN + readU + strings [message #19728] |
Mon, 17 April 2000 00:00  |
Ramji Digumarthi
Messages: 5 Registered: April 2000
|
Junior Member |
|
|
HI Folks,
I am having problem reading strings from spawned child process (a
C-routine). I can read variables (using ReadU :: thanks to comment from
David Fanning on pipes being binary). BUT if i read a string using
readu, the reading variables from child process go haywire... WHY???
HOW does the readU function treat the string variable??
any suggestions???
thanks
ramji digumarthi
|
|
|
Re: SPAWN + readU + strings [message #19857 is a reply to message #19728] |
Tue, 18 April 2000 00:00  |
Nigel Wade
Messages: 286 Registered: March 1998
|
Senior Member |
|
|
Ramji Digumarthi wrote:
>
> thanks to the reply from David Fanning about the reading the length of
> the string array.
> I forgot to mention that I do get the length of the string from the
> C-code, and I do read the string fine.
> the problem is on the next readu of variable...
> I get grabage.. IF the readU of the stirng commented out than
> the variable readU works fine .
>
> I am tryin to under stand what happens to readU with reading of the
> string??? I am also enclosing the both IDl and C-code...
>
>
> the C-code :::
> setbuf(stdout,(char *)0);
> strcpy(outStr,"Now opening the socket and waiting.\n");
> strOutlen=strlen(PoutStr);
> fprintf(stderr,"%i :: %d :: %s \r
> ",sizeof(strOutlen),strOutlen,outStr);
> write(1,&strOutlen,sizeof(int));
> write(1,outStr,sizeof(outStr));
>
Prepare to shoot me down if I'm wrong, but it looks to me as though
you are writing the wrong number of characters from the string
here. You don't tell us how you have declared outStr, but in C I
would think it is either a char pointer or a char array. The former
will have sizeof() = 4 (or 8 if a 64 bit system) and the latter will
be the length of the array regardless of what is in it.
Shouldn't you write strlen, or strOutlen bytes, which is the integer
you are writing before it as its length?
--
-----------------------------------------------------------
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
|
|
|
Re: SPAWN + readU + strings [message #19861 is a reply to message #19728] |
Mon, 17 April 2000 00:00  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
davidf@dfanning.com (David Fanning) writes:
> Ramji Digumarthi (ramji.digumarthi@lmco.com) writes:
>
>> WEll!! I tried that. Either temperary variable (actually recasting the
>> variable as long) or legitimate variable work as long as I do not read
>> the string variable. Once I read the string variable, the next readU of
>> a variable goes hay wire...
>> So what gives????
>
> I don't know. But I'm really not the person you should be talking
> to. And I wouldn't be trying to write strings anyway. I would
> be writing and reading byte values and casting them back
> to strings. Can't much go wrong that way. :-)
Amen to that. Read bytes, and then convert to a string at the end.
But your specific problem reminds me of a story: A man goes to the
doctor and says, "Doctor, it hurts when I do this." The wise doctor
said, "Then don't do that."
Seriously, if by *not* reading the string variable, everything works
fine, are you sure that the string is there?
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: SPAWN + readU + strings [message #19863 is a reply to message #19728] |
Mon, 17 April 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Ramji Digumarthi (ramji.digumarthi@lmco.com) writes:
> WEll!! I tried that. Either temperary variable (actually recasting the
> variable as long) or legitimate variable work as long as I do not read
> the string variable. Once I read the string variable, the next readU of
> a variable goes hay wire...
> So what gives????
I don't know. But I'm really not the person you should be talking
to. And I wouldn't be trying to write strings anyway. I would
be writing and reading byte values and casting them back
to strings. Can't much go wrong that way. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: SPAWN + readU + strings [message #19864 is a reply to message #19728] |
Mon, 17 April 2000 00:00  |
Ramji Digumarthi
Messages: 5 Registered: April 2000
|
Junior Member |
|
|
David Fanning wrote:
>
> Ramji Digumarthi (ramji.digumarthi@lmco.com) writes:
>
>> any comments on why this code does not work!!!!!
>>
>> readu,test,long(strInlen)
>> print," Test .. :",strInlen
>
> Well, you can't read into a temporary variable like this.
> Have you tried reading this value into a legitimate
> IDL variable? Does it still not work? I don't see anything
> obviously wrong, except for this.
>
> testVal = Long(strInLen)
> ReadU, test, testVal
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting
> Phone: 970-221-0438 E-Mail: davidf@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155
WEll!! I tried that. Either temperary variable (actually recasting the
variable as long) or legitimate variable work as long as I do not read
the string variable. Once I read the string variable, the next readU of
a variable goes hay wire...
So what gives????
thanks
ramji digumarthi
|
|
|
Re: SPAWN + readU + strings [message #19867 is a reply to message #19728] |
Mon, 17 April 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Ramji Digumarthi (ramji.digumarthi@lmco.com) writes:
> any comments on why this code does not work!!!!!
>
> readu,test,long(strInlen)
> print," Test .. :",strInlen
Well, you can't read into a temporary variable like this.
Have you tried reading this value into a legitimate
IDL variable? Does it still not work? I don't see anything
obviously wrong, except for this.
testVal = Long(strInLen)
ReadU, test, testVal
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: SPAWN + readU + strings [message #19872 is a reply to message #19728] |
Mon, 17 April 2000 00:00  |
Ramji Digumarthi
Messages: 5 Registered: April 2000
|
Junior Member |
|
|
thanks to the reply from David Fanning about the reading the length of
the string array.
I forgot to mention that I do get the length of the string from the
C-code, and I do read the string fine.
the problem is on the next readu of variable...
I get grabage.. IF the readU of the stirng commented out than
the variable readU works fine .
I am tryin to under stand what happens to readU with reading of the
string??? I am also enclosing the both IDl and C-code...
the C-code :::
setbuf(stdout,(char *)0);
strcpy(outStr,"Now opening the socket and waiting.\n");
strOutlen=strlen(PoutStr);
fprintf(stderr,"%i :: %d :: %s \r
",sizeof(strOutlen),strOutlen,outStr);
write(1,&strOutlen,sizeof(int));
write(1,outStr,sizeof(outStr));
read(0,&Next_data,sizeof(int));
fprintf(stderr," value read from parent : %d\r\r\n",Next_data);
strOutlen++;
write(1,&strOutlen,sizeof(int));
the IDL code :::
readu,test,strInlen
;string_in=string(replicate(32b,strInlen+1))
string_in=string(bytarr(strInlen))
readu,test,string_in,TRANSFER_COUNT=countVar
print,"Str len ::",strInlen," == ",string_in,countVar,size(string_in)
writeu,test,strInlen
readu,test,long(strInlen)
print," Test .. :",strInlen
----------------------------
any comments on why this code does not work!!!!!
thanks
ramji digumarthi
|
|
|