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
_______________________________________________
Ironpython-users mailing list
[email protected]
https://mail.python.org/mailman/listinfo/ironpython-users