redirecting STDIN/STDOUT

C

Christophe Helfer

hi,

I have some problem with redirecting input and output from a process.
Situation:
I have to use the Cisco Network Registrar (DNS And DHCP server) command
line utility as redirecting its input and output so I can interact with this
one. This utility is similar to ftp under a win32 console. It proposes its
own prompt after launching it.

What I want to do is:

- input some command (normally I have to write into the input stream)
- then get the response from the output stream.

This operations sequence must be repeated more than one time

I create a process with the right parameter such as useshell=false and
redirect in,out,err =true and app name =cmd.exe
(when I use directly app=<utility> it does not work)

when I write the command into the InputStream, I go a correct response into
the response stream but incomplete. In fact, there is one or more streams
behind the first one. You can get these streams if you pass in addition to
the peek function.
Then, after gathering the last stream the application freeze !

I already seek for code to achieve my goal but all code I've found doesn't
work for my situation
Code tested : VB.Net, VB and API, C/C++
How can I solve my problem, can anyone help me!

After many and many hours searching, I despair


Thanks a lot!
 
C

Christophe Helfer

I allready view the microsoft site and many other. Apparently I'm the only
one on earth who have this problem
 
C

Cor Ligthert

Hi Christopher,

I thought I had used this sample however it is not true, can you try this
one I made a short while ago (based on an MSDN sample), this is a sample for
the standardoutput I showed someone some days ago, so you have to make the
standardinput something the same.

Maybe this helps?

Cor

Dim p As New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.Arguments = "C:\Test1 C:\TestA\"
p.StartInfo.WorkingDirectory = "C:\windows\system32"
p.StartInfo.FileName = "xcopy"
p.Start()
Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
Dim sw As New IO.StreamWriter("C:\Test2\mytest.txt")
sw.Write(sb.ToString)
sw.Close()
 
H

Herfried K. Wagner [MVP]

* "Christophe Helfer said:
I have some problem with redirecting input and output from a process.
Situation:
I have to use the Cisco Network Registrar (DNS And DHCP server) command
line utility as redirecting its input and output so I can interact with this
one. This utility is similar to ftp under a win32 console. It proposes its
own prompt after launching it.

What I want to do is:

- input some command (normally I have to write into the input stream)
- then get the response from the output stream.

<URL:http://dotnet.mvps.org/dotnet/samples/miscsamples/downloads/RedirectConsole.zip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top