[Ironpython-users] Failing to read the standard output

Hemanth M B hemanth at broadcom.com
Thu Apr 9 06:58:17 CEST 2015


Hi All,

I am using System.Diagnostics namespace to spawn a console application. I want use asynchronous read and synchronous write, since the application is interactive. If I use synchronous read as mentioned below code, I need to close the stream writer before reading to end. Please help me to make code interactive.

Working Code:

import System
from System.Diagnostics import *
targetDir = "C:\\Users\\Administrator\\Desktop\\AMD64"
p = Process()
p.StartInfo.WorkingDirectory = targetDir
p.StartInfo.FileName = "C:\\Users\\Administrator\\Desktop\\AMD64\\WinFWUpg.exe"
#p.StartInfo.Arguments = "/c WinFWUpg.exe"
p.StartInfo.UseShellExecute = False
p.StartInfo.CreateNoWindow = False
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.Start()
sw = p.StandardInput
sr = p.StandardOutput
se = p.StandardError
print "success"
sw.WriteLine("dir\n")
sw.WriteLine("dev 1\n")
sw.Flush()
sw.Close()
print sr.ReadToEnd()


Not Working code:

import System
from System.Diagnostics import *
targetDir = "C:\\Users\\Administrator\\Desktop\\AMD64"
p = Process()
p.StartInfo.WorkingDirectory = targetDir
p.StartInfo.FileName = "C:\\Users\\Administrator\\Desktop\\AMD64\\WinFWUpg.exe"
#p.StartInfo.Arguments = "/c WinFWUpg.exe"
p.StartInfo.UseShellExecute = False
p.StartInfo.CreateNoWindow = False
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.Start()
sw = p.StandardInput
sr = p.StandardOutput
se = p.StandardError
print "success"
sw.WriteLine("dir\n")
while True:
    outline = sr.ReadLine()   /// Hangs here
    if not outline == None:
        print outline
    else:
        break
sw.WriteLine("dev 1\n")
sw.Flush()
sw.Close()
print sr.ReadToEnd()


Thanks and Regards,
Hemanth M B

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20150409/47cbb70c/attachment.html>


More information about the Ironpython-users mailing list