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!

can any one help me to "set path" unix command using tcl script?

Status
Not open for further replies.

rotomac

Technical User
Sep 24, 2003
13
US
Hi,

I just want to know how can i set the path in unix by using the tcl script.
ex:
if { $hera == 1 } { exec set path = /user/a } }

Thanks


 
If you want to modify the current script environment:
Code:
  set ::env(PATH) /user/a
If you want only to cd:
Code:
  cd /user/a
HTH

ulis
 
hi ulis,

I have some executable files under the directory /user/a/bin/hera and /user/a/bin/herb
The executable file name is x
so depends upon the variable hera or herb i want to select the path and execute file x.

Accroding to you i can set the path.after seting the path i could not run x. it says command x not found.

Between how to source the .cshrc file using tcl?

Thanks
roto
 
I understand that you have two executables: /user/a/bin/hera/x & /user/a/bin/herb/x, and a variable hera saying which one is to be executed.
In this case:
Code:
  if {$hera}   { set path /user/bin/a/hera/x }   else   { set path /user/bin/a/herb/x }
  exec $path
A more concise code:
Code:
  set here [expr {$hera ? "hera" : "herb"}]
  exec /user/bin/a/$here/x
More on exec at:
HTH

ulis
 
hi ulis,

It is working fine without error in tcl.but after adding the above path command if i use echo $PATH in unix command line option,it is not listing the path setted by tcl.

my requirement is,
we have some 6 to 7 excutable ore there in differant bin directory.according to variable setting i shoud set the path in unix and run the executables.
we are using alias command to set the path in .cshrc file for the above 7 differant excutables.
I thought of having a tk window and ask user to click the approprite executable and then use the exectable thru unix command.

so,i want to set the path = /home/user/abc thru tcl.
can you suggest me some solution?

Thanks
Roto
 
What I understand from your problem:
- you have some executables in different directories
- you want the user have only to click a name to launch an executable
- you have a variable i that indicates which executable to launch
- you have alias commands that generate csh scripts to cd

What I don't understand from your problem:
- from where comes the variable i?
- why the aliases?
----
Do you have a list of the name & the path of your executables?
If yes, I see a simple solution: a Tcl listbox that shows the executables names and able to lauch the selected executable:
Code:
  set ::execs   {
    {exec1 /usr/path1/exec1}
    {exec2 /usr/path2/exec2}
  }
  pack [listbox .lb]
  foreach item $execs   { .lb insert end [lindex $item 0] }
  bind .lb <<ListboxSelect>> { launch }
  proc launch {}   {
    set selected [lindex [.lb curselection] 0]
    if {$selected == &quot;&quot;} { return }
    set item [lindex $::execs $selected]
    foreach {name path} $item break
    toplevel .top
    wm title .top $name
    label .top.l -text &quot;launching...&quot; -fg blue
    pack .top.l -padx 50 -pady 50
    update
    if {[catch { exec $path & } msg]}     { # error
      wm title .top error
      .top.l config -text $msg -fg red
      after 5000 destroy .top
    }     else     { # all ok
      after 5000 exit 
    }
  }

HTH

ulis
 
To help us help you, it would be better you define your goal first, then the technical difficulties (if needed).

ulis
 
hi uis,

Thanks.your code works fine.But if i want to give some command line options for my executable how can i do that?
example:
{exec1 /usr/path1/exec1 -version}
{exec2 /usr/path2/exec2 -version}

If i give like this it is not taking -version option why?

Thanks
roto
 
Code:
  set ::execs   {
    {exec1 /usr/path1/exec1 {-opt1 -opt2}}
    {exec2 /usr/path2/exec2 {-opt3}}
  }
  pack [listbox .lb]
  foreach item $execs   { .lb insert end [lindex $item 0] }
  bind .lb <<ListboxSelect>> { launch }
  proc launch {}   {
    set selected [lindex [.lb curselection] 0]
    if {$selected == &quot;&quot;} { return }
    set item [lindex $::execs $selected]
    foreach {name path options} $item break
    toplevel .top
    wm title .top $name
    label .top.l -text &quot;launching $path $options...&quot; -fg blue
    pack .top.l -padx 50 -pady 50
    update
    if {[catch { eval exec $path $options & } msg]}     { # error
      wm title .top error
      .top.l config -text $msg -fg red
      after 5000 destroy .top
    }     else     { # all ok
      after 5000 exit 
    }
  }
The idiomatic construct:
Code:
foreach {name path options} $item break
needed to be updated. And so the list description & the exec command.

Alternativly you can only change the list description:
Code:
  set ::execs   {
    {exec1 &quot;/usr/path1/exec1 -opt1 -opt2&quot;}
    {exec2 &quot;/usr/path2/exec2 -opt3&quot;}
  }
without changing anything else but adding eval before exec.

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top