Export a Unix variable named File.
Brian K. White
brian at aljex.com
Wed Aug 2 15:11:16 PDT 2006
----- Original Message -----
From: "George" <gclute at comcast.net>
To: "'Kenneth Brody'" <kenbrody at spamcop.net>
Cc: <filepro-list at seaslug.org>
Sent: Tuesday, August 01, 2006 6:22 PM
Subject: RE: Export a Unix variable named File.
> Mssr: Brody Says:
> You need:
>
> export ascii exp=("/tmp/" { getenv("file")) r=\n f=, -x
> =============
>
>
> Thanks for the replies.
>
> What kind of fp environmental variable can I set to have getenv "file"
> provide a unique file name on every invocation? This simple export may
> run
> at random times per hour.
>
> Using: export ascii exp=("/tmp/" { getenv("file")) r=\n f=, -x
>
> Now it just writes a /tmp/.wp on every run.
>
> George Clute
So, you don't actually care if it comes from an environment variable? You
just want a new unique file each time?
That's simpler in that it can be done completely within filepro without
relying on the parent script to set things up.
It will look more complicated though.
First though, please run "configed" (or p, ?, F6) and put "PFADDWP=off" in
your config file.
That will stop fp from adding ".wp" to the filenames you specify in export
commands.
export word exp=("/tmp/"{doedit(@td,"yymd"){xlate(@tm,":",""){".csv")
explaination:
@td gives todays date as "mm/dd/yy"
doedit changes "mm/dd/yy" to "yyyymmdd" which does 3 useful things at once
changes the arrangement of yy mm dd so that the filenames will sort
naturally
changes the year to the full 4 digit year, also for correct sorting as
well as plain unambiguity
removes the slashes since they would not be good in a filename since they
would look like directories
@tm gives the current time to the second as "hh:mm:ss"
xlate strips the colons out of the @tm
All together it creates filenames like this:
/tmp/20060802130627.csv
That's only good enough if this is only run once it a while by one process
or one person. Like a cron job.
If it's on a menu or part of a cgi script where it's possible for anyone to
run it any time, then really the filename should more unique than that.
This will make a new filename every second, but 2 or 200 people could run it
at the same time and they'd all try to create the same exact file.
So the usual answer is a control file with a counter field.
This way every single invocation produces a new filename even if by some
fluke two people run the process at the same time.
This is a complete template/example export process that uses a counter file.
Assumes you have a filepro file named counters that has a field 10 defined
as (8,.0) and a record 1 already created in counters.
You'd create the table with normal define processing (no need for define
output, processing-only):
rcabe somefile export
and run it like this:
rreport somefile -fp export -u -s someselection -h "foo excel export"
----top of table----
if:
then: export word csv=(fn)
if:
then: csv(1) = 1
if:
then: csv(2) = 2
[...]
if:
then: end
@once: if:
if:
then: lookup counters r=("1") -ep
if:
then: fn(64,,g) = "/tmp/myexport_"{counters(10){".csv"
if:
then: counters(10) = counters(10) + "1" ; close counters
if:
then: system noredraw "umask 0;>"{fn
if:
then: end
----bottom of table----
It creates files named /tmp/myexport_########.csv
The data is csv format because that's what your original example would have
created, except this will put quotes around all the fields and will strip
leading and trailing spaces from each field.
That is almost always the safest and most correct way.
It's named .csv because again, generally it's less grief to name files
correctly so that there is the most chances for things to "just work".
Brian K. White -- brian at aljex.com -- http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
More information about the Filepro-list
mailing list