So i have a tcl code that i need to run in ns2. As we all know i just have to type 'ns abc.tcl' in terminal. In my abc.tcl code i have a variable x which i need to change and run the code. Is there any way i can write a script that will change the value of x and run 'ns abc.tcl' in terminal, then change the value again and run 'ns abc.tcl' in terminal again for a set of values for x. I believe i need to write a shell script but i don't know anything about that. Can you tell me the format i should write the script in like what should i write first and where do i write my values of x and how to make it run 'ns abc.tcl in terminal: 'function()' 'do' 'done' etc... If you can direct me to specific links about that would be helpful.
The easiest way, providing it works, is to pass the value in as an argument.
Invoke your code as ns abc.tcl TheValueToPassIn.
Access the value within your code by indexing into the argv global variable with lindex, which should contain a list of all arguments after the script name:
set myValue [lindex $::argv 0]
However, it's possible that that won't work (depending on exactly what the ns program does). If so, pass the value in inside an environment variable:
Invoke your code as MYVAR=TheValueToPassIn ns abc.tcl.
Access the value within your code by looking in the global env array:
set myValue $::env(MYVAR)
There are many other ways to do it, but those two are very easy.
Related
Let's consider the following situation:
I've created variabel as follows: my_var=32
I can read its value as follows: echo $my_var
I want to read address of this variable, but I can't figure it out.
Is it possible to perform it?
Is it possible to perform it?
Write a Bash builtin that will basically call var_lookup() with the variable name and then print SHELL_VAR address, or address of value.
You can also compile Bash with debugging symbols and inspect it with a debugger.
i have a tcl file and defining my environment variable inside that file. something like below
set env(ET_PINASSIGN_SCRIPT) $ET_PINASSIGN_SCRIPT
where $ET_PINASSIGN_SCRIPT variable will have a user incoming input value. Now I need to read this env variable in a shell file (#!/bin/ksh
). This is what i am trying and not working
$env ET_PINASSIGN_SCRIPT .
Any suggestions?
Thanks
I understand this is not possible. A program which is running, eg. your script, receives a duplicate of the environment, and can modify it. But when the program stops running, it disappears, together with its environment and changes.
There are few direct methods to communicate 'from the dead' process. You could create a temporary file, or return simple integers from the exit code.
Another way, would be to run the other program concurrently in a way that they share the same environment,
More info on the environment:
http://en.wikipedia.org/wiki/Environment_variable
Edit: I feel I wasn't clear enough: I just wanted to point out that programming that modifies the environment for other programs is 'extreme' (i.e. dangerous) programming. All kind of tricks can be done which can have lasting influences on the use of the computer.
The simplest method would be to make the Tcl code write a shell script to set the variable to standard out (with puts) and to then do:
eval `tclsh yourscript.tcl`
in your shell.
The Tcl code would probably be something like:
puts "ET_PINASSIGN_SCRIPT='$ET_PINASSIGN_SCRIPT'"
except you'll have to worry about any embedded ' characters, so might do…
puts "ET_PINASSIGN_SCRIPT='[string map {' '\\''} $ET_PINASSIGN_SCRIPT]'"
Is there a way to execute the start command with a variable as name. Actually, I need to provide a path that changes, but the filename is still the same, thus I decided to put a value in a user variable via Define or Accept
However, I receive error when I issue:
define name /home/andres/myfile.sql
start &name
-- Same error
start &name.
-- With an env variable, the same problem appears. (defining name in the shell)
start $name
start %name%
How can I execute a script with a dynamic name directly from SQLPlus? I know that I can do that from shell, but that will be platform dependent.
Finally, I am using CLPPlus, and that should have the same behavior as SQLPlus.
It seems to work for me on Unix. Next time please provide the error.
Your code errors : SP2-0136: DEFINE requires an equal sign (=)
Define needs an = sign.
dual.sql
select * from dual;
start.sql
start &1
define filename=/home/oracle/dual.sql
start &filename
Run script
SQL> #start dual
D
-
X
D
-
X
Basically, what I would like to do is to first set the arguments passed on launch by editing the scheme of current target, then access those arguments in the script, which I use as the post-action script.
I know I could use many build settings variables such as PRODUCT_NAME, but still can't find one to access arguments. If it is not possible, is there a walk-around? One awkward way I am thinking is to output the arguments to a txt file in my main.mm, then read them in my script. Thanks.
Is it possible to read binary in a Ruby file and execute it directly in memory?
For example, I want to do something like this:
x = IO.read('/bin/ls')
execute(x)
I tried system(x) but it returned:
ArgumentError: string contains null byte
I don't think you're going to be able to do that. When an executable starts, the dynamic linker needs to do quite a lot of fixing links up.
The simplest solution is to write the executable to a temporary disk file somewhere, and execute that.
system() and exec() both pass the command string to the OS to have it load and launch an external command, which isn't what you're asking to do.
For instance, this is from the system() documentation:
Executes command... in a subshell.
command... is one of following forms.
commandline:
command line string which is passed to the standard shell
cmdname, arg1, ...:
command name and one or more arguments (no shell)
[cmdname, argv0], arg1, ...:
command name, argv[0] and zero or more arguments (no shell)
Something could probably be written in C, as that is how Ruby is extended. There is lots of information on Google.