-1

I am executing isql command using python subprocess.I am using below code to capture output and error message.

command = "./isql -S "+mdbserver+" -U "+muserid+" -P "+mpassword+" -D "+mdatabase+" -s '"+self.Delimiter+"' -w 99999 <<EOF\nSET NOCOUNT ON\n"+Query+"\ngo\nEOF"
output, err = subprocess.Popen(command,stdout=subprocess.PIPE,shell=True,cwd=sybase_bin)

output and error of my isql command is coming in output variable. How to capture error message of isql in err variable.

Reetesh Nigam
  • 133
  • 2
  • 2
  • 15

1 Answers1

1

Use the stderr argument:

proc = subprocess.Popen(
    command,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    shell=True,
    cwd=sybase_bin
)

Then:

output, error = proc.communicate()

See the docs for more details.

Leo
  • 1,077
  • 11
  • 24
  • I am still getting error in output variable. I need to capture error in error variable – Reetesh Nigam Oct 27 '15 at 03:22
  • It might be that the errors are being reported through STDOUT in that case. You might need to check the docs and command line switches for isql. – Leo Oct 27 '15 at 08:31
  • I have added --retserverror in my -isql command. now I am getting error code in error variable. – Reetesh Nigam Oct 28 '15 at 05:54