How to shut down (LT) Spice after calculation

Discussion in 'Programmer's Corner' started by arben, Mar 10, 2014.

  1. arben

    Thread Starter New Member

    Mar 10, 2014
    1
    0
    Hello everyone

    I use Matlab to create netlists for LTspice, then I call LTSpice multiple times form Matlab using the "system" comando. Until now, I have to quit every LTSpice instance manually after calculations. Is there a way to do this automatically?
     
  2. ActivePower

    Member

    Mar 15, 2012
    155
    23
    I'm not sure if this fits the bill - just shooting in the dark here, but you could use MATLAB's timers to start and terminate system processes after specified amounts of time. This is just a hack but it'd probably work.

    To check, I just wrote a MATLAB script to automatically start and end a process under Windows 7.

    Here's the script (in entirety):
    Code ( (Unknown Language)):
    1. % HandleProcess.m
    2. % MATLAB Script to automatically initiate and close system processes
    3. % OS: Windows 7 (64-bit)
    4. %
    5. % System commands:-
    6. %   View all processes:     tasklist
    7. %   Kill process by name:   taskkill /IM
    8. %
    9. % Usage (from Command Line or another script)
    10. %       >> global PROCESS;
    11. %       >> PROCESS = 'ltspice.exe';
    12. %       >> HandleProcess();
    13.  
    14. %% Function to start process
    15.  
    16. function [] = HandleProcess()
    17.    
    18.     sysTimer = timer('TimerFcn', @(x, y)pause(1), 'Period', 10);
    19.    
    20.     % Start system process (Important: Append '&' to make it a background process otherwise timer won't terminate)
    21.     global PROCESS;
    22.     proc = [PROCESS, ' &'];
    23.     system(proc);
    24.  
    25.     sysTimer.StopFcn = @(~, ~)KillProcess;
    26.     start(sysTimer);
    27.  
    28. end
    29.  
    30. %% Function to kill processes
    31.  
    32. function [] = KillProcess
    33.    
    34.     global PROCESS;
    35.     cmd = 'taskkill /IM ';
    36.     command = [cmd, PROCESS];
    37.     disp(command);
    38.     disp('Killing process!');
    39.     system(command);
    40.  
    41. end
    42.  
    Maybe you could adapt it for your purpose.

    Hope this helps.
     
    Last edited: Mar 18, 2014
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Running it in batch mode might make it exit on completion (I'd have to look to be sure).

    There is a batch mode command line option (-b, if I remember right).
     
Loading...