From: Ian Jackson Date: Sun, 7 Jan 2018 20:14:43 +0000 (+0000) Subject: distort-stl: seems to handle pipes etc. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=commitdiff_plain;h=a54641e4bc6b596455d126117ecca44743f819e4 distort-stl: seems to handle pipes etc. --- diff --git a/distort-stl b/distort-stl index 863c8d1..da9b4ae 100755 --- a/distort-stl +++ b/distort-stl @@ -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 () { + @ARGV = @saved_argv; if (s/^\s+vertex\s+//) { my $lhs = $&; s/\s+$//; @@ -60,10 +67,12 @@ while () { @xyz = map { sprintf "%.18g", $_ } @xyz; $_ = "$lhs@xyz\n"; } - print O; + print $otmp $_; } -, if 0; # suppresses Name "main::I" used only once - close I; -close O; + if 0; # suppresses Name "main::I" used only once + +flush $otmp; + +system "admesh --normal-values $admesh_stdout $otmp";