Piping on solaris in exec()-function

Has anyone succeeded in making bodi exec() function to handle piping properly? :confused:

easy example:
“ls -l | grep bodi” should list all entries of the current directory (on jobserver) containig “bodi” e.g. as the owner.

The users-manual recommends to use a shell to do this. So on unix (sun os)
it should look like:

exec(‘sh’,‘-c 'ls -l | grep bodi'’,8 )

but the piping seems to be either ignored or leads to an error :reallymad:

I use di 6.5.1.10 and i think i reported this to the customer support for 6.0 already.
The workaround to put it in a shellscript still helps, but it is inconvenient and not very elegant at all.

Is this still a bug to be fixed or can i put the parameters in a correct order to make this work?


illo :de: (BOB member since 2005-06-07)

One workaround could be to create a shell script that will allow you you run arbitrary commands.

#!/bin/bash --posix
[ $# = 0 ] || exec <"$1"
	ln=0
	while read line ; do
		ln=$(($ln+1))
		echo $ln $line
	done

This might work. Call this shell script with parameter
‘ls -l | grep bodi’


shamit (BOB member since 2004-07-01)

Just put ls -l | grep ‘$1’ in a .sh and run exec(‘sh’, ‘my.sh’, 4);


TRS-80 :belgium: (BOB member since 2005-03-29)

By the way, remember that you can use awk in the same chain like I do for getting file size:

getfilesize.sh

#!/usr/bin/ksh
ls -al $1 | awk ‘{ print($5); }’

Called in the followinf way:

UNIX_GET_FILESIZE($FILENAME varchar(255)) Return int

IF (file_exists($FILENAME) = 1)
BEGIN
Return exec(‘getfilesize.sh’, $FILENAME, 4);
END
ELSE
BEGIN
Return 0;
END


TRS-80 :belgium: (BOB member since 2005-03-29)

Hi folks,
thank you for your answers, but i am looking for a way to do the trick without a shellscript. If i read the manual there is an example for windows and there is also a note that says if i want to use piping, i must point to a shell (like sh) in the first exec() parameter - which i did. (Without positive effect :frowning: )

Does this work on windows at least?
Is this a bug or should the “feature” be removed from the manual or am i still missing something :confused:

@ shamit: Your solution is a little more flexible than writing a script for any kind of problem - i guess i’ll try that for a better workaround (but it’s still a workaround, isn’t it? :wink: )


illo :de: (BOB member since 2005-06-07)