Subject: Re: gawk : Input file remaining locked after program termination
From: "Peter S Tillier" <[email-masked]>
To: "Cygwin" <[email-masked]>
Date: Mon, 16 Dec 2002 22:37:09 -0000

----- Original Message -----
From: "Capiez Lionel" <[email-masked]>
To: <[email-masked]>
Sent: Monday, December 16, 2002 1:26 PM
Subject: gawk : Input file remaining locked after program termination

> Hi,
>
> I have a gawk program that parses a file and spawns (as needed) an
external
> (non-gawk) program through the 'system(...)' built-in function. If the
> external program remains active after gawk's termination, the file
that was
> used as the input to gawk remains locked and can not be modified.
>
> Here is a code snippet the reproduces the issue :
> (Put both files in a dir. where you have a few .txt files)
>
> File foo.sh :
> -----------------
> ls *.txt > foobar
> gawk -f bar.awk foobar >foobar.tmp
> mv foobar.tmp foobar
>
> File bar.awk :
> -------------------
> {
> print $1 " OK";
> system("notepad " $1 " &");

This will attempt to spawn a copy of notepad for every line in the file
foobar in background and then returns the command's status.  In other
words gawk will not wait for the notepad command to complete before
moving to the next line in foobar and next instance of a notepad
process.
So there could be a number of incomplete notepad instances running, one
of which is trying to access foobar.tmp when the mv command is being
executed.  This may be causing the effect that you describe.

This did not happen when I tried your exact commands on my system.

> }
>
>
> Running foo.sh produced the following output :
> mv: cannot create regular file `foobar': Permission denied
>

This did not happen when I tried your exact commands on my system.

> And, as a side-effect, the 'foobar' file is deleted.
>

This did not happen when I tried your exact commands on my system.

> Would someone know whether this is a gawk issue ? a cygwin issue ? a
port of
> gawk to cygwin issue ? or my missing something ?
>

I don't think that this is a gawk issue - it may be your set up.
Which version of Cygwin are you using?

> As a side note, I tried to change the system call to
> system ("nohup " $1 " >/dev/null &")
> but to no avail.
>
> Thanks in advance for your help.
> Lionel
>

A few comments re: your gawk program.  This will fail if any of the
files have spaces in their names, because you are using $1 as the
name of the file to pass to notepad.  It would be more sensible to
use $0 and to quote it when passing it to notepad, i.e.:

    system ("notepad \"" $0"\" &")

Oh, and awk isn't perl, so you don't need to end lines with ";"

HTH
Peter
--
Peter S Tillier
"Who needs perl when you can write dc and sokoban in sed?"

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/