Page 1 of 1

Cannot Redirect Standard Error

PostPosted: Mon Aug 04, 2014 9:28 pm
by oahmad04
Please look at the following code:
use System.Diagnostics

class Input

def main

startInfo = ProcessStartInfo()

startInfo.fileName = 'cobra'
startInfo.arguments = 'fileWithErrors'
startInfo.useShellExecute = false

startInfo.redirectStandardOutput = true
startInfo.redirectStandardError = true

process = Process()
process.startInfo = startInfo


errorOutput = process.standardError.readToEnd.splitLines

for error in errorOutput, print "Standard Error:", error

It works fine, but if I set redirectStandardOutput to false, it stops working. Why do I have to redirect standard output to redirect standard error? Am I doing something wrong? Thank you. You guys are always kind and helpful. I appreciate that.

Re: Cannot Redirect Standard Error

PostPosted: Tue Aug 05, 2014 8:59 pm
by oahmad04
I think I figured it out. I didn't want to redirect standard output, because that messes with input. For example, if the program Process is running is supposed to print something before waiting for input, that something will end up being printed after because I am redirecting standard output and printing it all at the end. I edited my code so it redirects standard output, but prints it back to the console in real time. It seems to be working so far, but I still need to run some test cases.

Re: Cannot Redirect Standard Error

PostPosted: Tue Aug 05, 2014 9:11 pm
by oahmad04
Yeah, it works. Sorry to bother you for no reason.

Re: Cannot Redirect Standard Error

PostPosted: Wed Aug 06, 2014 12:31 am
by Charles
No worries.