[Thread Prev][Thread Next][Index]

Re: [ferret_users] How to pass the value from a ferret script to a c shell file ?



Hi-
Thanks for letting me know about your bounced message - that bouncing hasn't been an issue before so far as I know. People attach journal scripts and images to mail messages all the time, but maybe the fact that it was a shell script triggered this.

I also meant to address the original post about the idea of piping into Ferret. It's not individual long lines, but the total length in characters of the script; and it may no longer be the case with current versions of libraries like readline. It is solved with either

  ferret -script yourscriptfile.jnl [arguments]

or

  ferret<  yourscriptfile.jnl


  ferret<<EOF
   go yourscriptfile.jnl
  EOF


On 10/31/2011 7:40 PM, Ryo Furue wrote:
Hi Wen Chin and Ansley,

First of all, there is a confusion about the "piping issue".
Yes, there is a problem when Ferret reads commands, because
it can't read long lines from the standard input.  If your
script contain long lines, you have to use a script as

   ferret -script yourscriptfile.jnl

instead of

   ferret<  yourscriptfile.jnl

or of

   ferret<<EOF
   . . . contents of your script . . .
   EOF

On the other hand, there is no such problem in outputs from Ferret.
My solution simply processes outputs from Ferret.  I mentioned
the input piping issue just as a caveat because your original script
used the pipe "<<EOF".

| 2)For Ryo, strangely I couldn't find your reply. I found your reply
| embedded in Ansley's reply.

Your mailserver bounced my message because it thought my message
contained an unsafe attachment.  I just attached a shell script.
Well, a shell script IS an executable in a sense and could delete
all your files, set up a trojan horse, or something like that, yes.
So, I don't blame your mailserver :-)

This time, I'm just copying and pasting my original message
and the script below.

| In addition, when you mentioned
| "command_to_process_ferrets_output", could you give me an example?
| I assume the demonstration is
| an example written inside a shell script right?

Yes.  The "command" reads text lines and do whatever
you like with them.  And yes, you can define a "command"
within a shell script as well as call another script
if you prefer doing so.  What I don't know is how to
define a command in the C-Shell language.

Regards,
Ryo
----------------------------------------------------------
Hi,

| I do not know how to save the value
| of a variable in ferret script and pass that value to another
| variable in my c shell file.

Does anybody know how to suppress messages from Ferret other than
using the -script flag?  Without the "-script" flag, we have
startup messages like

	NOAA/PMEL TMAP
  	FERRET v6.61
         . . .

and "yes?" prompts.

For now, I use the "-script" flag, which complicates my solution
shown below.

In principle, you can "print" the value using the SAY
command of Ferret and capture it from your shell script.
It's the standard way of communication between processes
within a shell script.

I'm attaching a small demonstration. I use the Bourne Shell
because I don't know the C Shell well enough.

The basic idea is

   ferret<<STOP  | command_to_process_ferrets_output
   let a = 3.14
   say `a`
   quit
   STOP

where you read lines from Ferret in
command_to_process_ferrets_output .

But, if you do this, you end up seeing extra information printed
out by Ferret as I mentioned above.  So, in my demonstration,
I use the "-script" flag and a named pipe for the script.
Since it's a demonstration, I omitted error handling.

As an aside, a named pipe is necessary when your lines are long.
As far as I know, the maximum length of a line is a lot smaller
when reading the standard input than when reading a script file.

Regards,
Ryo
-----------------------
#/bin/sh
# This is just a demonstration or a template.

process_ferrets_output()
{
     while read line; do
	echo ferret said "$line"
     done
}

mypipe=tmp-pipe.jnl

mkfifo $mypipe
sleep 999999999>  $mypipe&   ## keeps the pipe from closing.
sleep_pid=$!

ferret -noverify -script $mypipe | process_ferrets_output&

cat<<'EOF'>  $mypipe
let a = 3.14
let b = "hello"
say `a`
say `b`
quit
EOF

kill $sleep_pid
rm $mypipe

wait


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement