-1

I have a .bat file that calls different things and runs different scripts to compile and build a system developed by other programmers. I am trying to call that .bat file from Python using Qprocess. The bat file runs smoothly. However, if the bat file by some reason fails, my python script needs to be terminated in some way.

I had a short discusion with some of the guys that wrote that huge .bat file and they told me that the .bat file has a standard structure and returns error levels if something is failed.

I don't really know how to catch those levels and I don't know so much about batch programming. Is Error level something universal? Can it be catched from Python?

I googled a bit and I found some very old articles that didn't teach me so much. Any one has a short example on how to catch those levels?

yacc
  • 2,915
  • 4
  • 19
  • 33
Payam30
  • 689
  • 1
  • 5
  • 20
  • Yes it is universal. All programs and batch commands return what is called, for programs, an Exit Code. See https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodeprocess. –  Apr 13 '20 at 06:42

1 Answers1

0

Error level in a batch file context means it will exit with a certain code. You can query this exit code as soon as the process finished.

def properties(self):
    self.process=QProcess()
    self.process.finished.connect(self.onFinished)
    self.process.start('test.bat', ['arg'])

def onFinished(self,  exitCode,  exitStatus):
    [check exit code here...]
yacc
  • 2,915
  • 4
  • 19
  • 33