Reputation: 171
I have this code in Python which runs perfectly well. What it does is it deletes files from a list on a filesheet. Now my question is if the cmd returns file not found could not delete how can I make Python aware of it so that I could put in a log the files I haven't deleted? I thought error handling would help but it wasn't an error in part of Python since I was just invoking the cmd through Python. Any ideas are welcome. :)
Example of how I invoke the cmd:
import os
os.system('CLS()')
Upvotes: 0
Views: 313
Reputation: 41
Here are the codes I was used and work well in Windows environment:
import subprocess
subprocess.call(["cmd"])
It's also available to accept more parameters as list in Python And it also could invoke your *.exe app to execute.
Upvotes: 0
Reputation: 27595
From the docs:
"The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes."
http://docs.python.org/library/subprocess.html
Upvotes: 1