1

I have to use matlab system function to call external process, but sometimes the process might be stuck in running and I want to force the process to shut down after certain time period, and then continue to run the remain codes. I know Time class could do some help, but such as 'kill/utime' could not be used on Windows system, would anyone mind pointing out suggestions, I'm grateful for any help.

fenfam
  • 63
  • 2
  • 9
  • [This](https://stackoverflow.com/a/56146305/6579744) may help. – rahnema1 May 16 '20 at 09:40
  • I am sorry that I'm not familiar with powershell, would you minding showing some simple codes to control the running time of the external process, thanks. – fenfam May 17 '20 at 10:16
  • In the linked post it is explained how to run a program (excel) and kill it. Simply copy/paste the code. But replace excel.exe with the name of your program. You don't need to be familiar with powershell. In the first line MATLAB uses powershell to start a program. In the scond lind the program is killed. – rahnema1 May 17 '20 at 11:05
  • Thanks for your advice, but in fact, I need to run cmd line to execute ABAQUS python scripts, it is something like "abaqus cae noGUI=xxx.cae/xxx.py" in normal cmd.exe or with system call in MATLAB, but I can not just substitute it with 'powershell (Start-Process abaqus cae noGUI=xxx.cae/xxx.py -passthru).Id)' in system powershell call in MATLAB. It always show errors with verifying file-path. – fenfam May 19 '20 at 11:57
  • I think you need to use - ArgumentList option. Please see [Start-Process](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-7) manual. If it doesn't work I think you need to convert your comment to a new question with powershell tag that how to start abaqus using powershell. – rahnema1 May 19 '20 at 18:00
  • Try 'powershell (Start-Process abaqus -ArgumentList "cae noGUI=xxx.cae/xxx.py" -passthru).Id)' – rahnema1 May 19 '20 at 18:29
  • Thanks, it did work. By the way, I needed a little modification as 'powershell (Start-Process abaqus -ArgumentList "cae noGUI=xxx.cae/xxx.py ask_delete=OFF" -passthru).Id)'. This line worked well in powershell, but in MATLAB system call, it could not identify the space between '.py' and 'ask_delte...' and show 'the positional form parameter that accepts the actual parameter "ask_delete=OFF" could not be found'. – fenfam May 20 '20 at 04:46
  • Both of these should work: `[~, pid] = system('powershell (Start-Process abaqus -ArgumentList ''cae noGUI=xxx.cae/xxx.py ask_delete=OFF'' -passthru).Id');` and `[~, pid] = system('powershell (Start-Process abaqus -ArgumentList \"cae noGUI=xxx.cae/xxx.py ask_delete=OFF\" -passthru).Id');` – rahnema1 May 20 '20 at 11:13

0 Answers0