delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/12/16/17:37:33

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <000401c2a553$adb84b00$5c16989e@oemcomputer>
Reply-To: "Peter S Tillier" <peter_tillier AT yahoo DOT co DOT uk>
From: "Peter S Tillier" <peter_tillier AT yahoo DOT co DOT uk>
To: "Cygwin" <cygwin AT cygwin DOT com>
References: <C1076CA8EF84D5119E960002A5753CF9D27912 AT multimedia DOT prosodie DOT com>
Subject: Re: gawk : Input file remaining locked after program termination
Date: Mon, 16 Dec 2002 22:37:09 -0000
Organization: Private
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

----- Original Message -----
From: "Capiez Lionel" <lcapiez AT prosodie DOT com>
To: <cygwin AT cygwin DOT com>
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019