DBM file handles close-on-exec ?

2007-05-07 Thread johan556
Hi!

I have a Perl script that opens a number of DBM files. It also starts
other programs via calls to system. I recently found out that the
handles to the DBM-files seem to be inherited by the newly started
process. I would like to avoid this. Does anybody know how to do this?

To demonstrate my problem I wrote the little script given below. It
uses notepad as an example of an external program that will inherit
the filehandles. To run the example I did:

  c:\ perl start-notepad.pl
  - Press Ctrl-C to terminate the Perl script.
  Terminating on signal SIGINT(2)
  c:\
  c:\ rm -f foo-dbm.dir foo-dbm.pag
  rm: cannot unlink entry foo-dbm.dir: The process cannot access the
file because it is being used by another process.
  rm: cannot unlink entry foo-dbm.pag: The process cannot access the
file because it is being used by another process.
  c:\

After terminating notepad I can remove the DBM files without problems.

/Johan Holmberg

#--
# start-notepad.pl

use Fcntl;
use SDBM_File;
use strict;

my %h;
my $status_file = foo-dbm;

tie(%h, SDBM_File, $status_file, O_RDWR|O_CREAT,0666)
or die Error: Can't open DBM file '$status_file': $!\n;

system notepad foo.txt;
#--
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: DBM file handles close-on-exec ?

2007-05-07 Thread Bill Luebkert
[EMAIL PROTECTED] wrote:
 Hi!
 
 I have a Perl script that opens a number of DBM files. It also starts
 other programs via calls to system. I recently found out that the
 handles to the DBM-files seem to be inherited by the newly started
 process. I would like to avoid this. Does anybody know how to do this?
 
 To demonstrate my problem I wrote the little script given below. It
 uses notepad as an example of an external program that will inherit
 the filehandles. To run the example I did:
 
   c:\ perl start-notepad.pl
   - Press Ctrl-C to terminate the Perl script.
   Terminating on signal SIGINT(2)
   c:\
   c:\ rm -f foo-dbm.dir foo-dbm.pag
   rm: cannot unlink entry foo-dbm.dir: The process cannot access the
 file because it is being used by another process.
   rm: cannot unlink entry foo-dbm.pag: The process cannot access the
 file because it is being used by another process.
   c:\
 
 After terminating notepad I can remove the DBM files without problems.

Try detaching the process and not inheriting :

use strict;
use warnings;
use Fcntl;
use SDBM_File;
use Win32::Process;

my $file = foo-dbm;

tie my %h, SDBM_File, $file, O_RDWR|O_CREAT, 0666
 or die Create '$file': $!($^E);

my $editor = 'D:\\Program Files\\Windows NT\\Accessories\\wordpad.exe';
if (0) {
system $editor web.txt;
} else {
my $pObj = CreateProcess ($editor, 'wordpad web.txt', 1);
}
sleep 10;

sub CreateProcess {
my ($exe, $cmdline, $detach) = @_;

my $pObj;
Win32::Process::Create ($pObj, $exe, $cmdline, 0, $detach ?
   DETACHED_PROCESS : NORMAL_PRIORITY_CLASS, '.') or
   die Win32::Process::Create: $!($^E);
return $pObj;

}

__END__
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Newline in CGI script

2007-05-07 Thread Andy_Bach
 The following code is live at http://www.biblescramble.com/Esther/x.cgi.

 I want to put newlines where the tabs are in $insert= Hazel Work 
states: 
WYrelocate: No;

 I've tried br, \n, etc. What do I need?

Not sure what you're after, exactly.  Perl will replace tabs by:
$insert =~ s/\t+/xxx/g;

Im using \t+ (one more tab chars) in case you've got tab tab tab and 
don't want 3 new lines - browsers will display new lines w/ BR so [1]:
$insert =~ s/\t+/br/g;

if you want to do it in the 'testing' java script function, its a little 
different.
$script2=function tester(){testing=\;
$script2.=$insert;
$script2.=\; var head1 = document.getElementById(\head1\); 
head1.firstChild.nodeValue=testing; return false;};

 java script has an RE package, which comes w/ the string object and a 
replace method,
http://www.devguru.com/technologies/ecmascript/QuickRef/string_replace.html

Note, using single quotes (as you've got no perl var being interpolated) 
will avoid the escapes of all you dbl quotes, so something like:
$script2 = 'function tester(){testing=';
$script2 .= $insert;
$script2 .= '; 
var test_regex = /\t+/g;
var result = testing.replace(test_regex, br\n);
var head1 = document.getElementById(head1); 
head1.firstChild.nodeValue = result; 
return false;}';

Untested, YMMV but that's the idea.

a

[1]
as a human readability issue, I always add a \n to Br tags (and P 
tags etc, so when you view source, its more legible:
$insert =~ s/\t+/br\n/g;


Andy Bach
Systems Mangler
Internet: [EMAIL PROTECTED]
VOICE: (608) 261-5738  FAX 264-5932

So it goes 
Kurt Vonnegut, Jr. (November 11, 1922 ? April 11, 2007) 
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs