kt0temp2010
New Member
Nooooo!
DOS has finally died (MS claimed this in Windows 3.1, but it only died in x64).
I have an old program which worked from the days of 286-AT to Vista-32.
Unfortunately, it no longer works in Vista/Win7 x64.
Code:
#include <stdio.h>
#include <stdlib.h>
void main (int argc, char *argv[])
{
FILE * lf_outfile ;
int lc_buffer ; // don't remember why I used 16-bit INT?
if (argc < 2)
{
lf_outfile = fopen ("NUL", "a+t")
}
else
{
lf_outfile = fopen (argv[1], "a+t")
}
while ((lc_buffer = getchar()) != EOF)
{
fwrite (&lc_buffer, 1, 1, stdout) ;
fwrite (&lc_buffer, 1, 1, stderr) ;
fwrite (&lc_buffer, 1, 1, lf_outfile) ;
fflush (lf_outfile) ; // flush to force save
}
fcloseall () ;
}
In simple terms, read input character-by-character, output to file (optional), stdout & stderr.
[expanded from a 'Programming 101' assignment, but probably the most versatile/most-used program I ever wrote.]
e.g.
C:\> someprogram.exe | PIPE logfile.txt | clip.exe
You may want the output saved into a log file, and yet, still stream it into another program...
Think about it, some things can take a while when running, it can "hang" there for hours, or hit errors or a state you don't want.
Having the output simultaneously on stderr, you can see what is going on.
(and yes, I flush to make sure the output file is saved if I need to hit Ctrl-Break)
I am wondering if this can be easily converted to Powershell (or any other better way).
Unfortunately, being new to PS, and searching common/generic words like "powershell pipe" is as good Gopher.
ps, Virtual Machines, DOSbox, etc, won't cut it, 'cos it will be taking input from things running locally on the base machine (e.g., defrag.exe -v|PIPE|clip).
DOS has finally died (MS claimed this in Windows 3.1, but it only died in x64).
I have an old program which worked from the days of 286-AT to Vista-32.
Unfortunately, it no longer works in Vista/Win7 x64.
Code:
#include <stdio.h>
#include <stdlib.h>
void main (int argc, char *argv[])
{
FILE * lf_outfile ;
int lc_buffer ; // don't remember why I used 16-bit INT?
if (argc < 2)
{
lf_outfile = fopen ("NUL", "a+t")
}
else
{
lf_outfile = fopen (argv[1], "a+t")
}
while ((lc_buffer = getchar()) != EOF)
{
fwrite (&lc_buffer, 1, 1, stdout) ;
fwrite (&lc_buffer, 1, 1, stderr) ;
fwrite (&lc_buffer, 1, 1, lf_outfile) ;
fflush (lf_outfile) ; // flush to force save
}
fcloseall () ;
}
In simple terms, read input character-by-character, output to file (optional), stdout & stderr.
[expanded from a 'Programming 101' assignment, but probably the most versatile/most-used program I ever wrote.]
e.g.
C:\> someprogram.exe | PIPE logfile.txt | clip.exe
You may want the output saved into a log file, and yet, still stream it into another program...
Think about it, some things can take a while when running, it can "hang" there for hours, or hit errors or a state you don't want.
Having the output simultaneously on stderr, you can see what is going on.
(and yes, I flush to make sure the output file is saved if I need to hit Ctrl-Break)
I am wondering if this can be easily converted to Powershell (or any other better way).
Unfortunately, being new to PS, and searching common/generic words like "powershell pipe" is as good Gopher.
ps, Virtual Machines, DOSbox, etc, won't cut it, 'cos it will be taking input from things running locally on the base machine (e.g., defrag.exe -v|PIPE|clip).