Modules in Bash or AWK

Christoph
Kitten
Kitten
Posts: 3
Joined: Sun Jul 24, 2005 8:57 pm
Location: Luxembourg
Contact:

Modules in Bash or AWK

Postby Christoph » Tue Jan 08, 2008 9:45 pm

Hi there,

for quite a while now I'm fumbling trying to get a working fvwm module written either as a shell or an awk script, but I never
really managed to get to the point where the module would be able to send commands to fvwm.
With the shell script I always get an error complaining about the sent string being to big.
With awk I even do not come to that point as I have no idea howto write to a file descriptor.
In one of the topics I read about a module written as a shell script but I didn't find any source code. It seems to be vanished...
The background is that my fvwm runs on a Zaurus and I try to avoid installing perl in order to save precious disk space.
On the other hand I would like to handle key bindings without the Exec command as it costs too much time to open
a shell each time you want to adjust the volume for mplayer.

Maybe one of you fvwm (or shell or awk) experts can help me by giving me some hints?

Thanks a lot in advance.

Christoph

thomasadam
Administrator
Administrator
Posts: 3043
Joined: Mon Nov 08, 2004 1:12 am
Location: England
Contact:

Re: Modules in Bash or AWK

Postby thomasadam » Tue Jan 08, 2008 9:48 pm

Christoph wrote:Hi there,

for quite a while now I'm fumbling trying to get a working fvwm module written either as a shell or an awk script, but I never
really managed to get to the point where the module would be able to send commands to fvwm.
With the shell script I always get an error complaining about the sent string being to big.


There was an unfinished attempt by someone to write sh bindings to talk to FVWM.

Christoph wrote:With awk I even do not come to that point as I have no idea howto write to a file descriptor.


Redirection.

Christoph wrote:Maybe one of you fvwm (or shell or awk) experts can help me by giving me some hints?


Maybe you can tell us what it is you're really trying to do -- it could simply be running an external script using FvwmCommand or just PipeRead suffices, rather than shooting yourself.

-- Thomas Adam

Christoph
Kitten
Kitten
Posts: 3
Joined: Sun Jul 24, 2005 8:57 pm
Location: Luxembourg
Contact:

Re: Modules in Bash or AWK

Postby Christoph » Wed Jan 09, 2008 9:41 am

Hi Thomas,

Maybe you can tell us what it is you're really trying to do -- it could simply be running an external script using FvwmCommand or just PipeRead suffices, rather than shooting yourself.


here comes my attempt in awk:

Code: Select all

#!/bin/bash

awk '

  BEGIN {
    send_text("\000");
    send_text("NOP FINISHED STARTUP");
    send_text("Echo Test");
  }

  function send_text(text) {
    print text
  }
 
' 1>&$1 <&$2


I would expect a "Test" in .xsession-errors. But nothing happens.

The shell module is nearly the same:

Code: Select all

#!/bin/bash
echo "0" >&$1
echo "NOP FINISHED STARTUP" "0" >&$1
echo "0" >&$1
echo "Echo Test" >&$1


Same result. Nothing in .xsession-errors.

The reasons I try to do this is that a Piperead or Exec would start a shell that e.g. would itself start an xmmsctrl command.
Increasing the volume that way wouldn't be very responsive as the Zaurus is simply too slow for that. So I thought of using
the xmms-pipe plugin with an fvwm-module that translates and passes the commands directly to the plugin. Same idea
with mplayer in slave-mode.
And, of course, I have kind of a sportive interest in just seeing if it is possible. :)

Christoph

frogb
Kitten
Kitten
Posts: 9
Joined: Fri Sep 29, 2006 8:22 pm

Re: Modules in Bash or AWK

Postby frogb » Sun Mar 23, 2008 8:02 am

Doesn't running a bash or awk script use the same resources for opening a shell as pipeexec? I tried it anyway
to see if it would work.

You have the module protocol slightly wrong. A message to fvwm is:
4 bytes for the window id
4 bytes for the message length
the message as an ascii string
4 bytes for continue (1 or 0)

With echo, the numbers have to be sent as binary by converting them to octal escape sequences. Also
echo adds a newline by default, which will affect the data.

So this is the bash fvwm module:

Code: Select all

#!/bin/bash

echo -ne "\000\000\000\000" >&$1
echo -ne "\024\000\000\000" >&$1
echo -n "NOP FINISHED STARTUP" >&$1
echo -ne "\001\000\000\000" >&$1

echo -ne "\000\000\000\000" >&$1
echo -ne "\011\000\000\000" >&$1
echo -n "echo Test" >&$1
echo -ne "\001\000\000\000" >&$1

thomasadam
Administrator
Administrator
Posts: 3043
Joined: Mon Nov 08, 2004 1:12 am
Location: England
Contact:

Re: Modules in Bash or AWK

Postby thomasadam » Sun Mar 23, 2008 1:36 pm

frogb wrote:With echo, the numbers have to be sent as binary by converting them to octal escape sequences. Also
echo adds a newline by default, which will affect the data.


Or just use printf.

-- Thomas Adam

unixfan2001
Kitten
Kitten
Posts: 1
Joined: Sun Apr 03, 2016 3:52 pm

Re: Modules in Bash or AWK

Postby unixfan2001 » Sun Apr 03, 2016 4:02 pm

I'm a wee bit late to the party, but did anyone pursue this further?
I cannot, for the life of me, get the posted code to work.

I'd like to take bash as a basis for an early prototype module, using it wrapped inside Haskell's Turtle Library.

The error I get when launching the module from the FVWM Commandline is the following:

Code: Select all

 [fvwm][module_receive]: <<ERROR>> Module(0x22d8b80) command is too big (5282239978490842958), limit is 1000

Lucio C
Kitten
Kitten
Posts: 9
Joined: Thu Jan 29, 2015 4:27 pm
Location: Milan Italy

Re: Modules in Bash or AWK

Postby Lucio C » Mon Apr 04, 2016 11:01 am

I have a crontab tcsh script which uses FvwmCommand, and another one which is called periodically by an FvwmScript invoked by the .fvwmrc (this pings a few local hosts and sets the colour of a little widget as green or red whether they respond or not). I have also another one called by a single PipeRead from .fvwmrc
Don't like the UI of Firefox > 29 ? Replace with Pale Moon: http://www.palemoon.org


Return to “Other languages”

Who is online

Users browsing this forum: No registered users and 1 guest