Hi,

On Fri, Aug 26, 2011 at 11:08:15AM -0700, msib...@crosswire.com wrote:
> Heres the wrapper if anybody is interested. It seems to work. 

What I was getting at before, was something like this:

    FvwmCommand -i2 'Test (EnvIsSet FOO) \
    SendToModule FvwmCommandS $[FOO]' | awk '$2 ~ string {print $3}'

Which you could obviously wrap in a shell script, and get to accept input,
etc.  It seems a little simpler than your perl example, although if there's
a need for this thing to persist in your case (you've still not actually
told me *what* use this is for, although at this point I suppose it doesn't
matter.)

Speaking of perl, I have some comments regarding your snippet.  I don't know
if this is just a toy to you or not, but if you're thinking of using this
for anything long-term, which is supposed to provide a service and which you
don't want to have crash, you might want to cast your eye over this.

> Thanks in advance!
> Matt
>  
> 
> #####################################################################
> #! /usr/bin/perl -w 

It's bad practise to do this in perl since there's now no selective way of
turning this off for other modules which include warnings.  It's better just
to use an explicit:

use warnings;

> # fvwm-getenv, a handy dandy tool for extracting environment variables 
> # from fvwm. 
> 
> use strict ; 
> 
> my $ev = shift @ARGV ; 
> chomp $ev ; 
> die ("usage: fvwm-getenv <environmentvariable> ") unless $ev =~ /\w+/ ; 

Perhaps better written as:

    die "...." unless @ARGV;
    chomp(my $ev = shift);

> # MAKE A FIFO
> my $mkfifo = '/usr/bin/mkfifo -m 700' ; # the mkfifo command 

Ouch!  This should be using the module:  File::Temp.

> my $tmppath = $ENV{'HOME'} . '/.fvwm/tmp' ; # you will need to create
> this directory

Again, can use File::Temp for this.

> my $rn = sprintf("%0.10d",rand(1000000000)) ; # a random number
> my $fifofn = $tmppath . '/' . $rn . '.fifo' ; # becomes a filename
> system("$mkfifo $fifofn") ; # and we create a temporary fifo

See:  POSIX qw/mkfifo/;

Also -- running *anything* through system in scalar content is a bad idea.

> # FVWM PASSTHROUGH COMMAND
> my $fvwmcommand = 'FvwmCommand ' . "'" . "Test \(EnvIsSet $ev\) Exec
> echo \$[$ev] >> $fifofn" . "'" ; 

This is the point at which I would have considered using FvwmPerl here (as
opposed to perllib outright.)

> my $childpid ; # know thyself
> 
> if ($childpid = fork) { # Parent
>  open (FIFOFN, $fifofn) ; #

The three-args form of open() is preferred these days.

>  my $line = readline(FIFOFN) ; # catch the input
>  print $line ; # print it
>  close(FIFOFN) ; 
>  unlink $fifofn ; # delete the tmp file
>  exit ;
> } else { # Child
>  system($fvwmcommand) ; # create the output

Again, heed advise about scalar context, and perhaps look in to FvwmPerl.

HTH,

-- Thomas Adam

-- 
"Deep in my heart I wish I was wrong.  But deep in my heart I know I am
not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.)

Reply via email to