[Thread Prev][Thread Next][Index]

Re: [ferret_users] spawn stops working

From a previous e-mail, Al's issue was with using a file in the second command that was created in the first command.  Under various operating systems and programs I have seen this situation - although the file created in the first command was closed out, it still takes the operating system a moment to mark the file as available for use.  But this behaviour would only be seen in scripts where the second command is executed immediately after the first command finishes.

As Ryo mentioned, the spawn command creates a shell and executes the command.  Note that this shell is not an normal interactive shell (it does not prompt for commands). 
So one possibility: If you have something in your shell initialization files (such as $HOME/.bashrc, $HOME/.cshrc, $HOME/.login) that needs some interaction (or sometimes even just prints something), this can cause an error or cause it to hang.  In initialization files you will see things like (for .C-type shells):

if (  $?prompt  ) then
   .... (commands) ...

or (for Bourne-type shells):

if [ "$PS1" ]; then
   ... (commands) ...

The commands inside these blocks are only executed in interactive shells.

You might want to try *temporarily* renaming your initialization file to see if it solves the problem with it hanging. 
If it does solve the problem, you probably need to add the appropriate test for an interactive shell around some of the commands in your initialization file.


On Tue, Nov 3, 2015 at 6:05 PM, Ryo Furue <furue@xxxxxxxxxx> wrote:
Al, Marco, and Ansley,

> I have sometimes experienced delayed or failed execution of sp commands.
> Just recently I was able to "fix" this by issuing a slight delay to allow my
> command to complete before continuing in my script:
> ...............
> sp my-linux-command
> sp sleep 1
> .............
> Is the intended default behavior of ferret to wait until the spawned command
> is completed before continuing in the script?

Ferret uses the "system" subroutine (as Ansley said), which (AFAIK)
waits until the command exits.  To see this, try

  yes? sp "sleep 5; echo hello"

What Fortran's "system" subroutine does is to pass the string to the
shell for the latter to execute.  So, it's basically the same as

  $ sh -c "sleep 5; echo hello"

on the command line.

So, I guess in your case,

> sp my-linux-command
> sp sleep 1

my-linux-command spawns subprocesses and exits without waiting for
them to complete.

I don't know what's causing Marco's problem, but if the SPAWN command
just hangs, that means the command it executes is hanging.  Do you see
some system messages (like /var/log/messages) that suggest some
problem like trying to mount an NFS filesystem . . . ?



Karl M. Smith, Ph.D.
JISAO Univ. Wash. and PMEL NOAA
"The contents of this message are mine personally and do
not necessarily reflect any position of the Government
or the National Oceanic and Atmospheric Administration."

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

Privacy Policy | Disclaimer | Accessibility Statement