Forums

Cannot Redirect Standard Error

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Cannot Redirect Standard Error

Postby oahmad04 » Mon Aug 04, 2014 9:28 pm

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

process.start
process.waitForExit

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.
oahmad04
 
Posts: 19
Location: Canada

Re: Cannot Redirect Standard Error

Postby oahmad04 » Tue Aug 05, 2014 8:59 pm

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.
oahmad04
 
Posts: 19
Location: Canada

Re: Cannot Redirect Standard Error

Postby oahmad04 » Tue Aug 05, 2014 9:11 pm

Yeah, it works. Sorry to bother you for no reason.
oahmad04
 
Posts: 19
Location: Canada

Re: Cannot Redirect Standard Error

Postby Charles » Wed Aug 06, 2014 12:31 am

No worries.
Charles
 
Posts: 2510
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron