On 11/30/2004 Jose Ambros-Ingerson <jose@kiubo.net> wrote:
It would be very convenient to be able to
run nrniv from a shell script and be able to execute a function call.
A line in this script would look something like:
$ nrniv funcdef.hoc -e "foo(p1,p2)"
which would mean "load file funcdef.hoc and then execute "foo(p1,p2)" where foo
was defined in funcdef.hoc and p1, p2 are parameters to this function.
Is there something like this available in Neuron?
I know that I could write:
$ cp funcdef.hoc tmp.hoc
$ echo "foo(p1,p2)" >> tmp.hoc
$ nrniv tmp.hoc
but I would prefer to avoid dealing with temporary files (they get tricky when
there are several instances of the script running in parallel).
Command line arguments?
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Here Documents
On 11/30/2005 Michael Hines <michael.hines@yale.edu> replied:
I generally use the shell feature called a "here" script. i.e
nrniv funcdef.hoc - << here
foo(p1, p2)
here
The sh man page states:
Here Documents
This type of redirection instructs the shell to read input from the
current source until a line containing only word (with no trailing
blanks) is seen. All of the lines read up to that point are then used
as the standard input for a command.
The format of here‐documents is:
<<[−]word
here‐document
delimiter
No parameter expansion, command substitution, arithmetic expansion, or
pathname expansion is performed on word. If any characters in word are
quoted, the delimiter is the result of quote removal on word, and the
lines in the here‐document are not expanded. If word is unquoted, all
lines of the here‐document are subjected to parameter expansion, com‐
mand substitution, and arithmetic expansion. In the latter case, the
character sequence \<newline> is ignored, and \ must be used to quote
the characters \, $, and ‘.
If the redirection operator is <<−, then all leading tab characters are
stripped from input lines and the line containing delimiter. This
allows here‐documents within shell scripts to be indented in a natural
fashion.
Here Strings
A variant of here documents, the format is:
<<<word
The word is expanded and supplied to the command on its standard input.
I generally use the shell feature called a "here" script. i.e
nrniv funcdef.hoc - << here
foo(p1, p2)
here
The sh man page states:
Here Documents
This type of redirection instructs the shell to read input from the
current source until a line containing only word (with no trailing
blanks) is seen. All of the lines read up to that point are then used
as the standard input for a command.
The format of here‐documents is:
<<[−]word
here‐document
delimiter
No parameter expansion, command substitution, arithmetic expansion, or
pathname expansion is performed on word. If any characters in word are
quoted, the delimiter is the result of quote removal on word, and the
lines in the here‐document are not expanded. If word is unquoted, all
lines of the here‐document are subjected to parameter expansion, com‐
mand substitution, and arithmetic expansion. In the latter case, the
character sequence \<newline> is ignored, and \ must be used to quote
the characters \, $, and ‘.
If the redirection operator is <<−, then all leading tab characters are
stripped from input lines and the line containing delimiter. This
allows here‐documents within shell scripts to be indented in a natural
fashion.
Here Strings
A variant of here documents, the format is:
<<<word
The word is expanded and supplied to the command on its standard input.
I tried it but it didn't work! When I have a file file.hoc with a single line in it containing printf("blabla\n") and I do
I just get the output blabla.
??
Code: Select all
neuron file.hoc - <<here
printf("blublu\n")
here
??
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
You told NEURON to read a hoc file and print a message.
It read the hoc file, printed the message, and exited.
To get it to do something else, like run a simulation,
make that one of the commands in your "here document."
If you're using the standard run system,
run()
would do the trick.
The only limitation to using here documents to set parameters
is that NEURON exits as soon as the last command is executed.
Not so great for interactive use.
It read the hoc file, printed the message, and exited.
To get it to do something else, like run a simulation,
make that one of the commands in your "here document."
If you're using the standard run system,
run()
would do the trick.
The only limitation to using here documents to set parameters
is that NEURON exits as soon as the last command is executed.
Not so great for interactive use.
No, it didn't exit.
The problem was, that the printf statement in the hoc file was executed, but not the printf statement in the here document.
Maybe the problem is, that cygwin doesn't understand here documents, though I didn't get any error message.
The same code executed from the bash results in execution of both printf statements.
The problem was, that the printf statement in the hoc file was executed, but not the printf statement in the here document.
Maybe the problem is, that cygwin doesn't understand here documents, though I didn't get any error message.
The same code executed from the bash results in execution of both printf statements.
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Under Linux or MSWin with cygwin?No, it didn't exit.
So under MSWin with cygwin, not Linux.The problem was, that the printf statement in the hoc file was executed, but not the printf statement in the here document.
Maybe the problem is, that cygwin doesn't understand here documents, though I didn't get any error message.
This under Linux, not MSWin with cygwin?The same code executed from the bash
results in execution of both printf statements.
The discussion side jumped to another topic:
http://www.neuron.yale.edu/phpBB2/viewtopic.php?t=234
The difference between Michael Hines' and Miller's observations are most likely due to using nrniv.exe instead or neuron.exe, but see the topic above.
http://www.neuron.yale.edu/phpBB2/viewtopic.php?t=234
The difference between Michael Hines' and Miller's observations are most likely due to using nrniv.exe instead or neuron.exe, but see the topic above.