Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cd in a tcl script

136 views
Skip to first unread message

Gunnar Törnblom

unread,
Aug 21, 1996, 3:00:00 AM8/21/96
to

I expected to get the new directory listed by the
puts - line below, but instead it list my old
default directory. Why ? ("usr/test" exists and is
a directory).

set drootdir "/usr/test"
if [file exists $drootdir] {
if {[file type $drootdir] != "link"} {
cd $drootdir
puts "PWD $env(PWD)"
} else {

Gunnar Törnblom

Neil Walker

unread,
Aug 21, 1996, 3:00:00 AM8/21/96
to

Hi

Gunnar Tornblom was asking about cd and pwd ...

I could talk about shells and processes, but I always get it wrong, so:

> tclsh
% puts "PWD in tcl = [pwd], outside = $env(PWD)"
PWD in tcl = /home/neilw, outside = /home/neilw
% cd tcl
% !p
PWD in tcl = /home/neilw/tcl, outside = /home/neilw
% exit
> pwd
/home/neilw

i.e. use the built-in pwd command!

Cheers
Neil


Jeffrey Hobbs

unread,
Aug 21, 1996, 3:00:00 AM8/21/96
to

In article <321AC6...@senet.abb.se>,

Gunnar Törnblom <gunnar....@senet.abb.se> wrote:
>I expected to get the new directory listed by the
>puts - line below, but instead it list my old directory.
> puts "PWD $env(PWD)"

env(PWD) doesn't correlate with 'cd' in Tcl. Use [pwd] (the
Tcl command) instead.

--
Jeffrey Hobbs office: 541.683.7891
Nomad of the 'Net email: jho...@cs.uoregon.edu
URL: http://www.cs.uoregon.edu/~jhobbs/

Gunnar Törnblom

unread,
Aug 22, 1996, 3:00:00 AM8/22/96
to

OK, but what I tried to do was really to change the current working dir
of the parent process because I will execute another (non-tcl) script that
require another directory (I am building a tcl/tk interface to an existing
application that I want to avoid to modify for compatibility reasons).

I suppose that what I must do is:

set env(PWD) $drootdir

Thanks to everyone who responded,

Gunnar Törnblom

Larry W. Virden

unread,
Aug 23, 1996, 3:00:00 AM8/23/96
to

According to Gunnar Törnblom <gunnar....@senet.abb.se>:
:OK, but what I tried to do was really to change the current working dir


:of the parent process because I will execute another (non-tcl) script that
:require another directory (I am building a tcl/tk interface to an existing
:application that I want to avoid to modify for compatibility reasons).
:
:I suppose that what I must do is:
:
: set env(PWD) $drootdir

1. Please !!! When someone is preparing to ask a question here on
comp.lang.tcl, ask the entire question. Many times explaining what
you are trying to do will result in discovering that the question you
are asking is the wrong question.

2. A child process can never set the working directory of the parent.

Doing the set above doesn't change the directory of anything. It may
make the current process _think_ it is in a different directory, but it
is not in fact so.
--
:s Larry W. Virden INET: lvi...@cas.org
:s <URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
:s Unless explicitly stated to the contrary, nothing in this posting should
:s be construed as representing my employer's opinions.

Gerald W. Lester

unread,
Aug 23, 1996, 3:00:00 AM8/23/96
to Gunnar Törnblom

Gunnar Törnblom wrote:

> OK, but what I tried to do was really to change the current working dir
> of the parent process because I will execute another (non-tcl) script that
> require another directory (I am building a tcl/tk interface to an existing
> application that I want to avoid to modify for compatibility reasons).

You can't do that. The OSes don't allow it. A process can only effect
itself and its children.

**********************************************************************
* Gerald W. Lester | Voice: +1 (504)-889-2784 *
* Computerized Processes Unlimited, Inc. | FAX: +1 (504)-889-2799 *
* 4200 S. I-10 Service Rd., Suite 205 | E-Mail: g...@cpu.com *
* Metairie, LA 70001 | WWW: http://www.cpu.com *
* "Consulting System Integrators" *
**********************************************************************

Scott Kruger

unread,
Aug 27, 1996, 3:00:00 AM8/27/96
to

In article <321E43...@cpu.com>, "Gerald W. Lester" <gwle...@cpu.com> writes:
>Gunnar Törnblom wrote:
>
>> OK, but what I tried to do was really to change the current working dir
>> of the parent process because I will execute another (non-tcl) script that
>> require another directory (I am building a tcl/tk interface to an existing
>> application that I want to avoid to modify for compatibility reasons).
>
>You can't do that. The OSes don't allow it. A process can only effect
>itself and its children.

I'm not sure I understand the original question, but it seems to me you can
do the stated goal although not in the manner suggested, at least on UNIX.

In my case, I wrote a script that executes a fortran code in the directory that
has the input file I need. Because of the way the code was written, the input file
has to be in the same directory. So I have:

cd $input_dir
exec ln -sf $code_dir/code . #This links the code to the current directory.
exec code #run the code.
cd $work_dir #Go back to the original directory
--
********************************************************************
* Scott Kruger Engineering Research Bldg *
* Center for Plasma 1500 Engineering Drive *
* Theory and Computation Madison, WI 53706 *
* http:/www.cptc.wisc.edu/~kruger/ Phone: (608) 263-0812 *
* kru...@cptc.wisc.edu Fax: (608) 262-6707 *
********************************************************************

Gerald W. Lester

unread,
Aug 27, 1996, 3:00:00 AM8/27/96
to

Scott Kruger wrote:
> In article <321E43...@cpu.com>, "Gerald W. Lester" <gwle...@cpu.com> writes:
> >Gunnar Törnblom wrote:
> >> OK, but what I tried to do was really to change the current working dir
> >> of the parent process because I will execute another (non-tcl) script that
> >> require another directory (I am building a tcl/tk interface to an existing
> >> application that I want to avoid to modify for compatibility reasons).
> >You can't do that. The OSes don't allow it. A process can only effect
> >itself and its children.
> I'm not sure I understand the original question, but it seems to me you can
> do the stated goal although not in the manner suggested, at least on UNIX.
> In my case, I wrote a script that executes a fortran code in the directory that
> has the input file I need. Because of the way the code was written, the input file
> has to be in the same directory. So I have:
> cd $input_dir
> exec ln -sf $code_dir/code . #This links the code to the current directory.
> exec code #run the code.
> cd $work_dir #Go back to the original directory

That was not what I read into the question. What I thought he was
asking was, from the unix shell do:

$ pwd
/home/gwl/test
$ my_tcl foo
$ pwd
/home/gwl/test/foo

Neil Walker

unread,
Aug 28, 1996, 3:00:00 AM8/28/96
to

Hi

>Gunnar Törnblom wrote:
>
>> OK, but what I tried to do was really to change the current working dir
>> of the parent process because I will execute another (non-tcl) script that
>> require another directory (I am building a tcl/tk interface to an existing
>> application that I want to avoid to modify for compatibility reasons).
>

If you used expectk you might avoid these problems, because you'd be calling
the other script from inside tcl. As far as I know, expectk still only (only?)
works on UNIX, which could be a problem ...

Cheers
Neil


Donal K. Fellows

unread,
Aug 28, 1996, 3:00:00 AM8/28/96
to

In article <321BFD...@senet.abb.se>,

Gunnar Törnblom <gunnar....@senet.abb.se> wrote:
> OK, but what I tried to do was really to change the current working dir
> of the parent process because I will execute another (non-tcl) script that
> require another directory (I am building a tcl/tk interface to an existing
> application that I want to avoid to modify for compatibility reasons).

This would be an _enourmous_ security hole, and consequently cannot be
done. Find a different way of doing what you want...

Donal.
--
Donal K. Fellows, (at work) | Donal K. Fellows, (at home)
Dept. of Computer Science, | 6, Randall Place, Heaton,
University of Manchester | Bradford, BD9 4AE
U.K. Tel: ++44-161-275-6137 | U.K. Tel: ++44-1274-401017
fell...@cs.man.ac.uk (preferred) | do...@ugglan.demon.co.uk (if you must)
--------------------------------------------------------------------------
<http://r8h.cs.man.ac.uk:8000/> for my home page

0 new messages