0

I created a process using os.system. I read that, normally, os.system should wait for it be completed, but I'm not sure it's the case in my code (I am calling an R script). How can I check whether the process is complete with os.sytem (I'd like to use os.system and not subprocess preferably)

Community
  • 1
  • 1
bigTree
  • 2,103
  • 6
  • 29
  • 45
  • Why don't you want to use subprocess? – wnnmaw Jul 03 '14 at 13:00
  • cause I wrote a bunch of os.system and would like to avoid rewriting all my code but if there is no way to do that with os.system then I will use subprocess – bigTree Jul 03 '14 at 13:00
  • I have some bad news for you, I don't believe there's any way to do what you want with ```os.system()```. Generally replacing should be as simple as replacing all your ```os.system()``` calls with ```subprocess.call()``` calls which you can do with find and replace function – wnnmaw Jul 03 '14 at 13:02
  • There's even a section of [the docs](https://docs.python.org/2/library/subprocess.html#replacing-os-system) devoted to this – wnnmaw Jul 03 '14 at 13:04
  • os.system doc "The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function" – bigTree Jul 03 '14 at 13:21
  • That should be a pretty good hint on what to do – wnnmaw Jul 03 '14 at 13:23

1 Answers1

3

If you want status code

ret = os.system('ls -l')
print ret
Nikhil Rupanawar
  • 4,061
  • 10
  • 35
  • 51