简体   繁体   中英

Reading / Writing to several launched processes command lines

I was wondering if it is possible to read the input stream / write to the output stream of several launched processes.

I'm asking this as from my current (weak) understanding of how reading / writing to launched processes work, it surely looks as it attaches the input / output streams to my program's console input / output stream.

Is this, indeed, the case? If that's the case, then reading/writing different data to several launched command lines would prove complicated, if not impossible, not achieve.

Is my understanding correct? How to deal with several launched command lines?


Some code:

open System
open System.IO
open System.Diagnostics
open System.Threading

[<EntryPoint>]
let main argv = 
    let startInfo = ProcessStartInfo()
    startInfo.FileName <- "cmd.exe"
    startInfo.UseShellExecute <- false
    startInfo.RedirectStandardInput <- true
    startInfo.RedirectStandardOutput <- true
    let proc = Process.Start(startInfo)
    proc.StandardInput.WriteLine("svn log")
    Console.ReadKey() |> ignore
    0

This code, as it is, will print

svn: E155007: 'C:\x\y\z\bin\Debug' is not a working copy

" it surely looks as it attaches the input / output streams to my program's console input / output stream."

Not true. You can tell the process to redirect stdin via myProcess.StartInfo.RedirectStandardInput . The Process object exposes methods to get to the input/output streams (eg Process.StandardInput ) to read/write them.

MSDN has some decent example code:

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardinput%28v=vs.110%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM