script file help

Hi, I'm runing a tool under unix. As soon as the tool is started, it will get into interactive mode. So I need to type in some command s like "run", "print" and so on. Is it possible to use a script file to input the commands instead of typing on the keyboard every time? Thanks a lot!

Gonna need a wee bit more information about the "tool" you speak of! Basically, you want to make an interactive session into a non-interactive session! Any particular reason? There is a scripting language called "Expect" that does this sort of thing. Cant tell you if it will work for you until you provide more details about what it is you are doing.

It will probably matter what the tool is and the OS/version you are running. You might want to post that information.

Otherwise, you can look into a product called Expect - if you search this site you will find postings about the product and what it is good for. Or check out Expect home page

(Looks like Google types quicker than I do!)

.....

Hi, Guys:
Thanks all of you so much!

The tool I'm using is "SPICE3", which is a circuit design tool. The environment in which I'm running is as follows:
Machine hardware: sun4u
OS version: 5.8
Processor type: sparc
Hardware: SUNW,Ultra-1

What I'm going to do is:

  1. Start the tool: SPICE3 circuit_example.sp
    where SPICE3 is the name of the tool, and circuit_example.sp is the file name where the circuit is saved.

  2. Then SPICE3 goes into interaction mode, waiting for more input from the keyboard. It looks like this:
    spice 1 ->

  3. Usually I type in "run" at this moment, and SPICE begin to run the circuit.

  4. After running, still in the interactive mode, I want to print out some results (like current and so on) and save them to the output file. What I'm doing is like this:

spice 2 -> print i(v1) i(v2) i(v3)+i(v4) > output1.txt

where, I was printing current i(v1), i(v2), and the summation of i(v3) and i(v4) to the output file, which is named output1.txt here.

  1. After I output all the results I want, I type in "quit", and SPICE3 will ask me "are you sure", then I type in "y", the SPICE3 then be closed.

So that's what I'm doing so far. I need to type in commands like that by hand. I'm trying to use different resistance, capacitance, and transistor parameters in the circuit to make the circuit give me a good performace. So for each group of parameter combination, if I do step 1 to step 5 by hand, it's quite a labor and wasting time. Therefore, I'm wondering whether the script file could do this work for me.

Any further help and comment will be greatly appreciated!

Hi, Druuna:
The file I was writing is like this:

#!/bin/csh -f
spice3 testdc.sp<<HERE
run
HERE

But it doesn't work, and the output of running this sript is:
"
Circuit: *test file for DC

Warning: no nodes given: .print i(vd)
Note: No ".plot", ".print", or ".fourier" lines; no simulations run
"

It's like spice3 is started, but "run" doesn't be excuted.

Did I use "HERE" in the right way?

Thanks a lot!

.....

The OP is using SunOS 5.8. While the SunOS csh man page does not mention "here documents" per se, it does have the following language...

     <<word
           Read the standard input, up to a line that is  identi-
           cal with word, and place the resulting lines in a tem-
           porary  file.  Unless  word  is  escaped  or   quoted,
           variable  and  command  substitutions are performed on
           these lines. Then, the pipeline is  invoked  with  the
           temporary file as its standard input. word is not sub-
           jected to variable, filename, or command substitution,
           and  each  line is compared to it before any substitu-
           tions are performed by the shell.

Hi, Druuna:
Thank you! I tried to move the input file name inside the HERE document, but it still doesn't work. It's true that spice3 lost track of inputfile, it just doesn't find the input file.

.....

Hi, Druuna:
I added -i following spice, and then this time it WORKS!!!

So I don't have to type in the commands every time!

Thanks a lot! I really appreciated your great help!

Have a good weekend!
:slight_smile: