相关疑难解决方法(0)

如何发送ctrl + z

如何转换ctrl+z为字符串?

我将此作为AT COMMAND发送到此计算机的连接设备.

基本上,我只是将一些字符放在字符串中以及ctrl+z字符串中

c# c++ string

7
推荐指数
2
解决办法
3万
查看次数

当StartInfo.RedirectStandardInput设置为true时,为什么StandardOutput.Read()会阻塞?

我很难解读有关Process.StandardOutpout的MSDN文档,以了解Read(Char [],Int32,Int32)方法是否阻塞.我的理解是它不应该阻塞,但是当我将RedirectStandardInput设置为true时它似乎就是这样.

有没有人有这方面的经验; 或者对我遇到的问题有一些解释?

这里的上下文是我不想等待整行(即使用行终止符),或者在读取标准输出之前退出进程.另外我不想使用回调.我想在进程写入时同步读取StdOut.

这是我的代码的简化版本:

string command = @"C:\flex_sdks\flex_sdk_4.5.1.21328\bin\fcsh.exe";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = false; # <-- if I set this to true, then 
                                           # the program hangs on
                                           # p.StandardOutput.Read later on
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = command;
p.Start();

StringBuilder sb_stdout = new StringBuilder(1024);
char[] buffer = new char[64];
int nb_bytes_read;
while (true) {
    do {
        nb_bytes_read = p.StandardOutput.Read(buffer, 0, buffer.Length);
        sb_stdout.Append(new string(buffer, 0, nb_bytes_read));
    } while …
Run Code Online (Sandbox Code Playgroud)

.net c# subprocess stdout process

5
推荐指数
2
解决办法
7479
查看次数

标签 统计

c# ×2

.net ×1

c++ ×1

process ×1

stdout ×1

string ×1

subprocess ×1