Is there a way to use ngspice command line without providing a circuit file? ex: passing the circuit as a string within the command line ?


Currently the only way I could use ngspice in command line is by providing an input file.. I could not find an example of using pipe mode though to pass netlist directly via command line without have to use a file to read from.

  • \$\begingroup\$ Isn't there a -p pipe mode for the program? Or do you mean something different? \$\endgroup\$ – jonk Jun 13 '19 at 5:30
  • \$\begingroup\$ can you please provide an example using the -p pipe mode? \$\endgroup\$ – simo Jun 13 '19 at 5:32
  • \$\begingroup\$ I don't use ngspice (or Kicad, which uses ngspice.) But I've heard about the pipe mode perhaps a decade ago. I'm just assuming it's still there. But I've never used it. (There was a problem in ngspice many years ago where outputting anything to a file would cause it to go into file block mode on the input and this made a mess of things. That's where I had heard about the feature. But it was fixed a long time ago, I think. I'm going on vague recollections. But those recollections do suggest to me that you should look into it. There's a manual, I'm sure.) \$\endgroup\$ – jonk Jun 13 '19 at 5:36
  • \$\begingroup\$ Possible duplicate of Running ngspice from command line on a Linux and Windows machine. \$\endgroup\$ – Huisman Jun 13 '19 at 7:08
  • \$\begingroup\$ If I do understand your question, you would like something like: ngspice "voltage divider netlist V1 in 0 1 R1 in out 1k R2 out 0 2k .end" ... How do you get this string in the first place? \$\endgroup\$ – Huisman Jun 13 '19 at 12:27

As commented before, the Window GUI version of ngspice will not work with pipes due to a Windows specific I/O handling.
Maybe you could try finding a workaround.

I think you should have the GUI write the netlist to a file called e.g. "circuit.cir" and have the code of the GUI execute ngspice circuit.cir.

Another option having the GUI making a string based on the netlist and using a batch file which parses the netlist string, writes it to (e.g.) "circuit.cir" and lastly, executes ngspice circuit.cir.
Make sure you seperate each line of the netlist with a unique character (e.g. ¶ or ­§ or whatever) when making one big string of it.

  • \$\begingroup\$ I don't want to use any GUI, I just want to be able to pass netlist to ngspice without using a file but I have no idea about the pipe mode, can you please share an example of passing netlist using pipe mode? \$\endgroup\$ – simo Jul 10 '19 at 8:35
  • \$\begingroup\$ Any update about this? \$\endgroup\$ – simo Jul 18 '19 at 12:39
  • \$\begingroup\$ @simo I hardly use ngspice. As said it won't work on Windows and I don't have linux. So, I'm afraid I can't help \$\endgroup\$ – Huisman Jul 18 '19 at 12:45
  • \$\begingroup\$ No worries, thank you \$\endgroup\$ – simo Jul 18 '19 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.