This is a mirror of official site: http://jasper-net.blogspot.com/

Looking at the problem at the wrong level: Closing a process's stdin

| Thursday, July 7, 2011
A customer was having trouble manipulating the stdin stream that was given to a process.

    How do you simulate sending Ctrl+Z to a hidden console process programmatically?

    I am using Redirect­Standard­Input and want to send the console a Ctrl+Z. I've tried sending ASCII code 26, but that doesn't work. Generate­Console­Ctrl­Event supports Ctrl+C and Ctrl+Break but not Ctrl+Z.

    Here's what I'm doing, but it doesn't work:

    ProcessStartInfo info = new ProcessStartInfo(@"...");
    info.CreateNoWindow = true;
    info.RedirectStandardError = true;
    info.RedirectStandardOutput = true;
    info.RedirectStandardInput = true;
    info.UseShellExecute = false;
    Process p = Process.Start(info);
    // 0x1A is ASCII code of Ctrl+Z but it does not work
    p.StandardInput.WriteLine("\x1A");

The customer was kind enough to do more than simply ask the question. The customer set up the scenario and even provided a code fragment that illustrates the problem. Which is good, because the original question was the wrong question.

The customer asked about simulating typing Ctrl+Z to a console, but what they actually doing was sending a character to stdin; they weren't sending it to a console. In fact, the way they created the process, there is no console at all.

Read more: The old new thing
QR: 10183368.aspx

Posted via email from Jasper-net

0 comments: