Index: trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
===================================================================
--- trunk/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 17829)
+++ trunk/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 17963)
@@ -1,5 +1,5 @@
 # Copyright (c) 2006  Paul Price, Joshua Hoblitt
 #
-# $Id: Config.pm,v 1.87 2008-05-28 20:28:46 jhoblitt Exp $
+# $Id: Config.pm,v 1.88 2008-06-06 23:46:57 bills Exp $
 
 package PS::IPP::Config;
@@ -11,6 +11,9 @@
 
 use Carp qw( carp );
+use File::Basename qw( basename dirname );
 # use File::Spec 3.19;
 use File::Spec 0.87;
+use File::Temp qw( tempfile );
+
 use PS::IPP::Metadata::Config 1.00;
 use Getopt::Long 2.33 qw( GetOptions :config gnu_getopt pass_through ); # Set pass_through so we don't kill @ARGV
@@ -510,4 +513,58 @@
                                           exit($PS_EXIT_DATA_ERROR));
     return 1;
+}
+
+# create a (possibly) temporary file with name (basename $_[0])
+# if $preserve create a file named basename$_[0] in current directory
+
+sub create_temp_file
+{
+    my $self     = shift;
+    my $pathname = shift;
+    my $preserve = shift;
+
+    die "pathname must be defined" unless ($pathname);
+
+    my $fileRef;
+    my $fileName;
+
+    # we only use in the last part of the path
+    my $base = basename($pathname);
+
+    if ($preserve) {
+        # we want to keep the file just create it in the current directory 
+        $fileName = "./$base";
+        open $fileRef, ">$fileName" or die "can't open $fileName for output";
+    } else {
+        #  we really want a tempfile, so put it in /tmp
+        ($fileRef, $fileName) = tempfile("/tmp/$base.XXXX", UNLINK => 1);
+    }
+
+    return ($fileRef, $fileName);
+}
+
+# redirect stderr and stdout streams to a file
+sub redirect_output
+{
+    my $self = shift;
+    my $name = shift;
+
+    die "need name" unless $name;
+
+    my $filename = $self->file_resolve($name, "--touch");
+
+    die "cannot resolve $name" unless $filename;
+
+    # We need to make sure the directory for this file exists
+    # If it's a nebulous file it has already been created so the directory must exist
+    # we won't run mkdir there
+    my $dir = dirname($filename);
+    if (! -d $dir) {
+        my $rc = system "mkdir -p $dir";
+        die "failed to create directory for $filename" unless (!$rc);
+    }
+
+    open STDOUT, ">>$filename" or die "failed to redirect stdout to $filename";
+    open STDERR, ">>$filename" or die "failed to redirect stderr to $filename";
 }
 
