How to set Field Separator for TCLSH??? :S

Hi,
I am having a problem, with setting the FS in TCLSH, maybe someone knows the answer.

I have a Tclsh/Tk script, and i�m trying to get all (only) the running processes for the given user like this:

foreach process [exec ps -u $user -o command] \{
        puts stdout $process;
\}

This also works, but not in that way as I want.
executing this "ps -u $user -o command" in the command line will give me an output like that:

COMMAND
/usr/lib/bonobo/bonobo-activation-server --ac-activate --ior-output-fd=16
sshd: a72093@notty
tcsh -c /usr/bin/nxnode --startsession

BUT, when I am trying to execute in the foreach loop, it will give me an output like this

COMMAND
/usr/lib/bonobo/bonobo-activation-server
--ac-activate
--ior-output-fd=16
sshd:
a72093@notty
tcsh
-c
/usr/bin/nxnode
--startsession

How can I set the FS that way, that the output lines wouldnt be splitted by "space" ?

Thank you.

Hi.

For this specific problem, this appears to be a simpler solution:

#!/usr/bin/env tclsh

# @(#) s1     Demonstrate method for printing results from exec.

set version [ info tclversion ]
set message " Hello, world from tclsh ($version)."
puts stdout $message
puts stdout ""

set m [ exec ls -1gG ]
puts stdout $m

Producing:

% ./s1
 Hello, world from tclsh (8.4).

total 8
-rw-r--r--  1 182 Dec 19 05:30 readme.txt
-rwxr--r--  1 246 Dec 19 05:40 s1

Best wishes ... cheers, drl

PS. In future posts, please enclose code and data in CODE tags. The easy way to do this is to highlight the text in the edit window with your mouse, then click the # button just above the editing window.

Hi.

I was thinking that the OP may wish to do processing on specific lines and not just printing. Here is an extended example showing a way to do that:

#!/usr/bin/env tclsh

# @(#) s3     Demonstrate method for printing results from exec.

set version [ info tclversion ]
set message " Hello, world from tclsh ($version)."
puts stdout $message
puts stdout ""

puts " As results from command substitution:"
set m [ exec ls -1gG ]
puts stdout $m

puts stdout ""
puts stdout " With foreach loop on list:"
foreach i [ list [ exec ls -1gG ] ] {
  puts stdout $i
}

exit 0

Producing:

% ./s3
 Hello, world from tclsh (8.4).

 As results from command substitution:
total 16
-rw-r--r--  1 182 Dec 19 05:30 readme.txt
-rwxr--r--  1 246 Dec 19 05:40 s1
-rwxr--r--  1 754 Dec 19 08:37 s2
-rwxr--r--  1 415 Dec 19 08:40 s3

 With foreach loop on list:
total 16
-rw-r--r--  1 182 Dec 19 05:30 readme.txt
-rwxr--r--  1 246 Dec 19 05:40 s1
-rwxr--r--  1 754 Dec 19 08:37 s2
-rwxr--r--  1 415 Dec 19 08:40 s3

Best wishes ... cheers, drl

Reference to consider:

Title: Practical Programming in Tcl and Tk
Author: Brent Welch, Ken Jones
Edition: 4th
Date: June 20, 2003
Publisher:
ISBN: 0130385603
Pages: 960
Categories: programming, text processing, GUI
Comments: 3.5 stars, 41 reviews (2008.12)
Comments: (I have 3rd edition)