English 中文(简体)
"exec source <script>" does not work in tcl
原标题:
  • 时间:2010-02-22 14:57:51
  •  标签:
  • unix
  • tcl
  • csh

I m trying to call a script in Tcl with the command:

exec source <script path>

and I get the error

couldn t execute "source": no such file or directory

How can I call another script from tcl?

Edit: I am running a command I got from another person in my office. I was instructed to run "source " explicitly with source. So in other words, how would I run any command that would work in cshell, in Tcl?

最佳回答

source in csh, like . in bash, executes a script without spawning a new process.

The effect is that any variable that is set in that script is available in current csh session.

Actually, source is a built-in command of csh, thus not available from tcl exec, and using exec without source would not give the specific source effect.

There is no simple way to solve your problem.

问题回答

If the script you were given is a cshell script, you can exec it like this:

exec /bin/csh $path_to_script

In effect, this is what the source command does from within an interactive shell. It s not clear whether this is really what you want to do or not (not exactly, but close enough for this discussion).

The reason you can t exec the source command is that exec will only work on executable files (hence the name exec ). The source command isn t implemented as an exectuable file, it is a command built-in to the shell. Thus, it can t be exec d.

If you really feel the need to exec the source command or any other built-in command you can do something like this:

exec /bin/csh -c "source $path_to_script"

In the above example you are execing the c shell, and asking it to run the command "source ". For the specific case of the source command, this doesn t really make much sense.

However, I m not sure any of this will really do what you expect. Usually if someone says "here s some commands, just do source , it usually just defines some aliases and whatnot to be used from within an interactive shell. Those aliases won t work from within Tcl.

source load the source file

you should do:

source <script path>

If you want to execute it, then you need to call the main proc.

another option would be to do:

exec [info nameofexecutable] <scritp path>

Some confusion here. exec runs a separate program, possibly with arguments. source is not a separate program, it is another Tcl command which reads a file of Tcl commands and executes them, but does not pass arguments. If the other script you are trying to call is written to be run on from the command line, it will expect to find its arguments as a list in variable argv. You can fake this by setting argv to the list of arguments before running source, eg.

set argv {first_arg second_arg}
source script_path

Alternatively you could use exec to start a whole separate Tcl executable and pass it the script and arguments:

exec script_path first_arg second_arg

the error speaks for itself. Make sure you give the correct path name, specify full path if necessary. and make sure there is indeed the file exists in that directory

Recently I wanted to set some UNIX environment variables by sourcing a shell script and stumbled across the same problem. I found this simple solution that works perfectly for me:

Just use a little 3-line wrapper script that executes the source command in a UNIX shell before your Tcl script is started. Example:

#!/bin/csh
source SetMyEnvironment.csh
tclsh MyScript.tcl




相关问题
Generate assembler code from C file in linux

I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I m getting errors. I m trying to build an ...

Function to create the array by reading the file

I am creating scripts which will store the contents of pipe delimited file. Each column is stored in a separate array. I then read the information from the arrays and process it. There are 20 pipe ...

Compare characters at the end of the string C++

This program supposed to find command line arguments entered on Unix which ends with “.exe”. For some reason it doesn t work. Here is the code: int main( int argc, char* argv[] ) { for ( int ...

Batch Job Dependencies Using Open Source/Free Software

I run a large data warehouse plant where we have a lot of nightly jobs running concerruently however many have dependencies on a extract or data load process before they start. Currently we use an ...

Writing application for both Unix and Windows

I ll write a program for Interactive UNIX (http://en.wikipedia.org/wiki/INTERACTIVE_UNIX). But in a year it will be ported to Windows. I ll write it in ANSI C and/or SH-script. When it runs on Windows ...

Development Environment in Windows [closed]

What are your recommendations for setting up a development environment in Windows, especially when not using an IDE. I am attempting to familiarize myself with Windows, and I feel a bit lost. What ...

热门标签