in reply to Shelling a new process with console I/O in Windows

D'oh! This is true, problem is lacking in problem. The problem is that I'm not getting a new console window for the shelled program. Everything's staying in the original console (which I care less about), and more to the point not turning STDIN back over to the keyboard, which makes interactive programs like aspell much harder to use. This means that "perl -w aspell_filter.pl README.TXT" works just fine, but "type README.TXT | perl -w aspell_filter.pl" doesn't. The latter is, unfortunately, the whole reason for putting this together in the first place. I've taken the variable of aspell out of the mix by replacing the call with CMD.EXE for now, just to see what's going on. Here's the entire program again, with the changes, and all of the initial 'use's.
use strict; use IO::File; use File::Temp qw(tempfile); use Win32::Process; use Win32; # Create a temporary file to hold the input. my ($fh, $filename) = tempfile(); # And stream everything into it. my $linecount = 0; while (<>) { $fh->print($_); $linecount++; } print STDERR "Wrote $linecount lines to $filename.\n"; # Now pass the input off to aspell for processing my $obj; my $appname = "C:\\windows\\system32\\cmd.exe"; my $cmdline = "/K dir"; my $iflags = 0; my $cflags = NORMAL_PRIORITY_CLASS + CREATE_NEW_CONSOLE; my $curdir = "."; Win32::Process::Create( $obj, $appname, $cmdline, $iflags, $cflags, $curdir) or die "Couldn't shell to aspell.\n"; $obj->Wait(INFINITE); # Return the tempfile on standard output seek($fh, 0, 0); while (<$fh>) { print } print "Check complete."
Sorry for the initial screwup. Anyone got any thoughts? I'm not tied to the idea of a second console, or using Win32::Process directly, I'm just looking for the moral equivalent of:
STDIN = console input; STDOUT = console display; system("stuff"); STDOUT = back to the redirected version;

Replies are listed 'Best First'.
Re^2: Shelling a new process with console I/O in Windows
by BrowserUk (Patriarch) on Mar 11, 2009 at 00:33 UTC

    There is still no clear explanation of what exactly you are trying to achieve with your code? Rather than posting more code, please try to explain what it is that you are trying to achieve.

    For example, one reading of the words you've posted so far is that you want to:

    1. start an executable from a perl program, passing it a filename via the command line;
    2. Allow the user to interact with that program via the console;
    3. Have the perl script capture the output from the program;
    4. Then print that output on the (same?) console.

    But if that is a correct reading, I cannot see how you thought the code you've posted so far was ever going to acheive that--so, perhaps I mis-reading the words?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.