Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running backgound program from TCL 2

Status
Not open for further replies.

jhahs

Technical User
Oct 19, 2004
29
US
Trying to get TCL to execute a program and have that program run in the backgroud while TCL does other stuff.

The external program is a "C" program, it works from the UNIX command line, The C program cannot be started before the TCL as it takes different parameters depending on what the TCL scripts gets.
here is the the TCL command:
catch {exec ~/csp/audits/user/cspnsl_builder $NE_Handle}ErrMsg

$NE_Handle is the parm that is set to the C program.
Thought about using a pipe, but not sure how to do it.
I can get an Expect script to run it, but when you call the expect script from TCL, it will not run. Here is the expect script..
set Header [lindex $argv 0]
set force_conservative 1
if {$force_conservative} {set send_slow {1 .1}; proc send {ignore arg} {exp_sleep .1; exp_send -s -- $arg}}
if { [fork] != 0 } then exit
disconnect
set env(TERM) vt100
spawn $env(SHELL)
match_max 100000

send -- "~/csp/bin/cspnsl_builder $Header &\r"

Any suggestion??
 
I wouldn't try to control it in any fashion from within expect unless you really need to get output from the spawned process.

Why not just use fork alone?
Code:
if {child = [fork] == 0} {
   if {catch [exec ~/csp/bin/cspnsl_builder $Header] err_exec}{
          puts "Child exec of ~/csp/bin/cspnsl_builder with argument $header: $err_exec"
    }
}

 
Hi,

using a pipe is this easy:

Code:
if {[catch {open "|~/csp/audits/user/cspnsl_builder $NE_Handle" r} pipe]} {
    puts "Cannot open pipe because:\n$pipe"
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top