chiark / gitweb /
distort-stl: seems to handle pipes etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Jan 2018 20:14:43 +0000 (20:14 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Jan 2018 20:14:43 +0000 (20:14 +0000)
distort-stl

index 863c8d124705711650a35b98ae4e93b2f8bb8bab..da9b4aef89e4fa65ef756d14ed4cb0a7877dafd9 100755 (executable)
@@ -22,6 +22,8 @@
 use strict;
 use autodie;
 
+use File::Temp;
+
 sub shift_arg () {
     die unless @ARGV;
     scalar shift @ARGV;
@@ -41,14 +43,19 @@ if (@ARGV && $ARGV[0] =~ m/^-/) {
     die "no options supported\n";
 }
 
-my $admesh_pipe = '--write-ascii-stl 3<&0 4>&1 >/dev/null /dev/fd/4 /dev/fd/3';
+my $itmp = new File::Temp;
+my $otmp = new File::Temp;
+
+system "cat >$itmp";
+
+my $admesh_stdout = '--write-ascii-stl /dev/fd/3 3>&1 >/dev/null';
 
-open I, "admesh $admesh_pipe |";
-open O, "| admesh --normal-values $admesh_pipe";
+open I, "admesh $admesh_stdout $itmp |";
 
 our @saved_argv = @ARGV;
 
 while (<I>) {
+    @ARGV = @saved_argv;
     if (s/^\s+vertex\s+//) {
        my $lhs = $&;
        s/\s+$//;
@@ -60,10 +67,12 @@ while (<I>) {
        @xyz = map { sprintf "%.18g", $_ } @xyz;
        $_ = "$lhs@xyz\n";
     }
-    print O;
+    print $otmp $_;
 }
 
-<I>,<O> if 0; # suppresses Name "main::I" used only once
-
 close I;
-close O;
+<I> if 0; # suppresses Name "main::I" used only once
+
+flush $otmp;
+
+system "admesh --normal-values $admesh_stdout $otmp";