Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Is it possible to get the working directory in Windows gawk?
(I am currently using gawk 3.1.0 under Windows XP)

I have a compiler that outputs error messages using relative file names

I am trying to filter the stderr output so the file names are absolute path
names
rather than relative, so I can use the Visual Studio "find next error"
facilities (and
I am not in the directory of the files being compiled that generated the
message -
lot of directory changes and nmakes in the build process)

I have no problems piping the error output through a filter program, but the
problem is, the filter program needs to know the working directory to be
able
to prepend it to the file names.

Under Windows, I can get the current directory in the variable %cd%, for
example
echo %cd%
returns the same as
cd
(or in *nix/*nux)
pwd

I tried to pipe output using a command like this (dir/b is only an example):

dir /b | gawk -f c:\rvsawk\addpath.awk curpath=%cd%

The problem is the \ directory separators are interpreted as special
characters,
of course.  If I typed it in manually, I would use a double \\ so the string
would
get the backslash.

Is there an internal variable or a way to access this from awk?  "cd"
doesn't come
up as a regular environment string with the set command so I couldn't use

ENVIRON["CD"]

to get it, though other variables, like:

ENVIRON["HOMEPATH"]

work okay.

Anyone know of a way?

Rufus



Report this thread to moderator Post Follow-up to this message
Old Post
Rufus V. Smith
12-04-04 01:55 AM


Re: Is it possible to get the working directory in Windows gawk?
On Fri, 3 Dec 2004 16:15:25 -0500, "Rufus V. Smith"
<nospam@nospam.com> wrote:

>dir /b | gawk -f c:\rvsawk\addpath.awk curpath=%cd%

I find this confusing - I find that / workes better than \ in the
script name.  It is unclear what "curpath=%cd%" is supposed to
accomplish - "-vcurpath=%cd%" would be clear.

In any case,
dir /b /s
returns fully qualified filespecs (but includes any subdirectories).

Backslashes are not an issue in strings read from the input.

You can use DIR without /b, and extract the directory name from the
header and the file names from the body of the report.

BEGIN{
"CD" | getline
BaseDir = $0
close( "CD")
}
puts the output of the CD command into $0 as input andthen into
BaseDir while preserving the backslashes.


T.E.D. (tdavis@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.

Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
12-04-04 01:55 AM


Re: Is it possible to get the working directory in Windows gawk?
Make a batch file containing:

set here=%cd%
dir /b | awk95 -f addpath.awk

You awk program should have:

BEGIN { curpath=ENVIRON["here"] }

Report this thread to moderator Post Follow-up to this message
Old Post
William James
12-04-04 08:55 AM


Re: Is it possible to get the working directory in Windows gawk?
On Fri, 3 Dec 2004 16:15:25 -0500, "Rufus V. Smith"
<nospam@nospam.com> wrote:

>dir /b | gawk -f c:\rvsawk\addpath.awk curpath=%cd%

I find this confusing - I find that / workes better than \ in the
script name.  It is unclear what "curpath=%cd%" is supposed to
accomplish - "-vcurpath=%cd%" would be clear.

In any case,
dir /b /s
returns fully qualified filespecs (but includes any subdirectories).

Backslashes are not an issue in strings read from the input.

You can use DIR without /b, and extract the directory name from the
header and the file names from the body of the report.

BEGIN{
"CD" | getline
BaseDir = $0
close( "CD")
}
puts the output of the CD command into $0 as input andthen into
BaseDir while preserving the backslashes.


T.E.D. (tdavis@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.

Report this thread to moderator Post Follow-up to this message
Old Post
Ted Davis
12-07-04 08:59 AM


Re: Is it possible to get the working directory in Windows gawk?
Make a batch file containing:

set here=%cd%
dir /b | awk95 -f addpath.awk

You awk program should have:

BEGIN { curpath=ENVIRON["here"] }

Report this thread to moderator Post Follow-up to this message
Old Post
William James
12-07-04 08:59 AM


Re: Is it possible to get the working directory in Windows gawk?
"Rufus V. Smith" <nospam@nospam.com> wrote in message
news:1102108503.u8/1dXablCG7XJCeEG6V8A@teranews...
> (I am currently using gawk 3.1.0 under Windows XP)
>
> I have a compiler that outputs error messages using relative file names
>
> I am trying to filter the stderr output so the file names are absolute
path
> names
> rather than relative, so I can use the Visual Studio "find next error"
> facilities..

<snip>

I finally came up with the following combination:

NMAKE LINE:

----
$(MAKE) /$(MAKEFLAGS) $(LIBDIR)\$(*B).l 2>&1 | gawk -f
/rvsawk/addpath.awk xx=%cd% yy=zz
----

This pipes stderr and stdout through the single stdout pipe  into the gawk
filter.
The %cd% does return the current directory


GAWK SCRIPT:
----
BEGIN {
cd=substr(ARGV[1],4,999) "\\";
#print "cd = " cd
}
substr($0,1,1)=="\"" { $1 = "\"" cd substr($1,2,999)
}
{print $0}
----

In order that awk doesn't process the %cd% backslashes as escape
characters, I pull the cd string out of argv[1].

Interestingly, I have to put that additional filler :  yy=zz at the end of
the line, otherwise the end of the line gets truncated and I get
%cd
as the directory name.


Rufus





Report this thread to moderator Post Follow-up to this message
Old Post
Rufus V. Smith
12-07-04 08:59 AM


Re: Is it possible to get the working directory in Windows gawk?
"Rufus V. Smith" <nospam@nospam.com> wrote in message
news:1102352600. 81f323c92e6bbce4e9ae0cda3d5f6bba@teranew
s...
>
> "Rufus V. Smith" <nospam@nospam.com> wrote in message
> news:1102108503.u8/1dXablCG7XJCeEG6V8A@teranews... 
> path 
>
> <snip>
>
> I finally came up with the following combination:
>
> NMAKE LINE:
>
> ----
>     $(MAKE) /$(MAKEFLAGS) $(LIBDIR)\$(*B).l 2>&1 | gawk -f
> /rvsawk/addpath.awk xx=%cd% yy=zz
> ----
>
> This pipes stderr and stdout through the single stdout pipe  into the gawk
> filter.
> The %cd% does return the current directory
>
>
> GAWK SCRIPT:
> ----
> BEGIN {
> cd=substr(ARGV[1],4,999) "\\";
> #print "cd = " cd
> }
> substr($0,1,1)=="\"" { $1 = "\"" cd substr($1,2,999)
> }
> {print $0}
> ----
>
> In order that awk doesn't process the %cd% backslashes as escape
> characters, I pull the cd string out of argv[1].
>
> Interestingly, I have to put that additional filler :  yy=zz at the end of
> the line, otherwise the end of the line gets truncated and I get
> %cd
> as the directory name.
>
>
> Rufus


A new wrinkle, it turns out the error code returned is the code of the
filter program,
not the compiler generating the output, which is inconvenient, though it
makes sense.

So now I have to parse the output for an "NMAKE error code" line, extract
the
error code and exit the awk script with the same error code value if
I want the build to terminate.

Anyone know a better way (in windows) to propagate the error status past
the filter program?  For example, can the filter program get the status from
the prior program?

I've been trying to avoid turning this into a batch file call.

Rufus

Gee, now that I say this, there may be an %errorstatus% or something like
that
I can append to that command line.   Stay tuned...



Report this thread to moderator Post Follow-up to this message
Old Post
Rufus V. Smith
12-07-04 08:59 AM


Re: Is it possible to get the working directory in Windows gawk?
"Rufus V. Smith" <nospam@nospam.com> wrote in message
news:1102377899. d4fb40926008a690728feed58e160fb2@teranew
s...
>
> Gee, now that I say this, there may be an %errorstatus% or something like
> that
> I can append to that command line.   Stay tuned...
>

Yes, there is an %errorlevel%
No, it's 0 when the filter is run.

ah, well.  sticking to parsing.




Report this thread to moderator Post Follow-up to this message
Old Post
Rufus V. Smith
12-07-04 08:59 AM


Re: Is it possible to get the working directory in Windows gawk?
> cd=substr(ARGV[1],4,999) "\\";

cd=substr(ARGV[1],4) "\\"


Report this thread to moderator Post Follow-up to this message
Old Post
William James
12-07-04 08:59 AM


Re: Is it possible to get the working directory in Windows gawk?
"William James" <w_a_x_man@yahoo.com> wrote in message
news:1102383463.618562.303080@c13g2000cwb.googlegroups.com... 
>
> cd=substr(ARGV[1],4) "\\"
>

Thanks!!  Mine's a throwback to more ancient languages...

Rufus



Report this thread to moderator Post Follow-up to this message
Old Post
Rufus V. Smith
12-07-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:04 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.