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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't cd to another directory within tcl/tk script

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
US
I need to tar files from different directories, but I DON'T want the fully qualified path prefixing each file name. The way I'm getting the list of files to tar is by using the variable set by a find cmd that specifies the full path.

ex.
>set LOF [eval exec find /some/dir/path -name "*.c"]
>exec tar -cvf newtarfile.tar [lindex $LOF 0 end]

I would like to cd to the "/some/dir/path" prior to executing the find cmd.
 
additional info ...

Yes, I tries to simply "cd" to the new directory to no avail. I suspect my PATH needs to be modified, but how?
I'm running on solaris 2.8...


Note(s): I'm using specTcl (which is a gui for creating guis). I've had great success using this tool. Also I'm
using prowrap to create standalone executables.
 
All of your environment variables are held within the
env array.
parray env for starters.
 
I can't understand why "cd" to a directory doesn't work in the first place. If the only solution is indeed to monkey with the environment variable(s), how do I begin?
 
cd works in a non specTcl script ... thus anyone know why it DOESN'T work within specTcl ???
 
Odd. There should be no reason that a Tcl script can't cd to a directory unless the directory doesn't exist or you don't have permission to read and search the directory. This should have absolutely nothing to do with environment variables at all.

Just to check, are you using Tcl's built-in cd command to change the working directory of the script?

Code:
cd /some/dir/path

Or are you using exec to run a cd command?

Code:
exec cd /some/dir/path

If it's the latter, then it will have no effect on your Tcl script whatsoever. In this example; the Tcl exec command starts a separate process, which runs the cd command and then exits. - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Ken, thanks for the response. I can't explain what had happen because NOW it works (and no, I didn't prefix the cd cmd with an "exec"). ..and yes the dir did exist and I have the correct permissions ...

Basically, when initially I couldn't get it to work, I was simply trying to ..
>cd /some/dir/path/
>puts [exec pwd]
...and this wasn't working. It was always giving me the dir of the specTcl executable.

Then I went and created a generic script (without specTcl) and invoked it through wish8.3 .. and it worked!

Went back to my specTcl script, and now it works thru specTcl. I'm perplexed !!!!

Thanks for the quick response, what a great forum!!!
 
Hm. That's very odd. I'd have to take some time to test it out on a few different OSs to see if things behave differently than I expect based on the OS. Oh, well...

Anyway, another tip: Tcl has a buil-in pwd command. No need to exec pwd.

And something else I should have mentioned earlier, the Standard Tcl Library, tcllib, has some file utilities that includes a Tcl version of find (so once again, you wouldn't have to exec find and your script could be more platform independent). For information on tcllib, go to the Tcl'ers Wiki ( and check out the page "tcllib," - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top