This can't be as difficult as I'm making it out to be. I'm trying to write a wrapper around 'aspell -c', which takes a filename, opens the file interactively in the console to be spell checked, and saves the changes back to the file. What I want to do is, in short:
- Slurp all of the STDIN, write it to a temp file
- Run that temp file through an aspell session, for which locally STDIN/STDOUT are the keyboard and a console window respectively
- Wait until aspell terminates
- Write the revised temp file back out STDOUT.
And here's what I've been trying.
# 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:\\Program Files\\Aspell\\bin\\aspell.exe";
my $cmdline = "--check $filename";
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
}
Any thoughts on what I'm doing wrong?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.