[MKDoc-commit] [1.6] stop using lib::util::Command (backported from 1.8)

bruno at mkdoc.demon.co.uk bruno at mkdoc.demon.co.uk
Fri Feb 10 15:34:21 GMT 2006


Log Message:
-----------
[1.6] stop using lib::util::Command (backported from 1.8)

Tags:
----
mkdoc-1-6

Modified Files:
--------------
    mkd/flo/editor:
        Html.pm

-------------- next part --------------
Index: Html.pm
===================================================================
RCS file: /var/spool/cvs/mkd/flo/editor/Html.pm,v
retrieving revision 1.7.2.28
retrieving revision 1.7.2.29
diff -Lflo/editor/Html.pm -Lflo/editor/Html.pm -u -r1.7.2.28 -r1.7.2.29
--- flo/editor/Html.pm
+++ flo/editor/Html.pm
@@ -24,7 +24,6 @@
 package flo::editor::Html;
 use flo::Standard;
 use flo::Editor;
-use lib::util::Command;
 use MKDoc::Util::Text2HTML;
 use MKDoc::Config;
 use strict;
@@ -159,6 +158,56 @@
 }
 
 
+sub sysexec($$$)
+{
+    my $cmd = shift;
+    my $tmp_dir = shift;
+    my $in  = shift;
+    Encode::_utf8_off ($in);
+    
+    my $out = undef;
+    my $err = undef;
+    
+    my $tmp = $$ . '.' . time . '.' . int (rand (10000));
+    my $tmp_out = $tmp_dir . '/' . $tmp . '.out';
+    my $tmp_err = $tmp_dir . '/' . $tmp . '.err';
+    
+    if (defined $in)
+    {
+	# executes the command and writes to temp files
+	open FP, "|$cmd 2>$tmp_err >$tmp_out" or
+            die "Cannot open pipe to $cmd: $!";
+	print FP $in;
+	close FP;
+    }
+    else
+    {
+	# executes the command and writes to temp files
+	system ("$cmd 2>$tmp_err >$tmp_out") or
+	    die "Cannot exec $cmd: $!";
+	print FP $in;
+	close FP;
+    }
+    
+    # reads the command standard output
+    open (FP, $tmp_out) or
+	die "Cannot read-open file $tmp_out: $!";
+    $out = join '', <FP>;
+    close FP;
+    
+    # reads the command error output
+    open FP, "<$tmp_err" or
+        die "Cannot read-epen file $tmp_err: $!";
+    $err = join '', <FP>;
+    close FP;
+    
+    # tidy all the mess and returns $out and $err
+    unlink $tmp_out;
+    unlink $tmp_err;
+    return ($out, $err);
+}
+
+
 ##
 # $obj->html_tidy;
 # ----------------


More information about the MKDoc-commit mailing list