8-bit DOS program

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).
 

My Computer

My Computer

System One

  • Manufacturer/Model
    HP Pavilion m9515y
    CPU
    Phenom X4 9850
    Memory
    8 GB
    Graphics Card(s)
    Some Radeon Cheapie with 512 MB Ram
    Monitor(s) Displays
    CRT
    Screen Resolution
    1280x1024
    Hard Drives
    750 GB SATA 3G
    2 SIIG Superspeed docks w/WD Caviar Black Sata II or III
Thanks for the heads-up.

Linux tee is close, but not quite (2-way split)...

e.g., program.exe|tee file.txt|clip.exe
would hang there until the whole operation is complete

The pipe splitting program also outputs to stderr, (3-way split) so
program.exe|pipe file.txt|clip.exe
would also show the output in 'real-time' to the 'dos' window...
 

My Computer

If it's a command line text manipulation it's been done in Linux, believe me.. just look through the man pages. It's already been done probably in 1980.
 

My Computer

System One

  • Manufacturer/Model
    HP Pavilion m9515y
    CPU
    Phenom X4 9850
    Memory
    8 GB
    Graphics Card(s)
    Some Radeon Cheapie with 512 MB Ram
    Monitor(s) Displays
    CRT
    Screen Resolution
    1280x1024
    Hard Drives
    750 GB SATA 3G
    2 SIIG Superspeed docks w/WD Caviar Black Sata II or III
Thanks...

BTW, 1980? it's a decade off - more like 1990... ;-)

I started programming in 1982, on an Apple ][ (48kB RAM) -- CALL -151
I wrote the program above probably 1990, first compiled on Borland C compiler for DOS6, then also ported to Linux 0.99.09 (80 floppy disks! downloaded 1 disk a day due to BBS download limits)

For some 20 lines lines of code, it worked, so I didn't bother to check if someone else wrote it, however, I cannot believe that nobody else ever needed that requirement either!

Again, the problem of searching for something too generic (no specific keywords), it is hard to find.
 

My Computer

I'm talking about the Unix program that was stolen, er, ported to Linux. Most of that command line executable pipe tool stuff is reworked Unix tools. Also look at Perl, Awk and sed "one liners".

Try this page to start:
Native Win32 ports of some GNU utilities
 

My Computer

System One

  • Manufacturer/Model
    HP Pavilion m9515y
    CPU
    Phenom X4 9850
    Memory
    8 GB
    Graphics Card(s)
    Some Radeon Cheapie with 512 MB Ram
    Monitor(s) Displays
    CRT
    Screen Resolution
    1280x1024
    Hard Drives
    750 GB SATA 3G
    2 SIIG Superspeed docks w/WD Caviar Black Sata II or III

My Computer

System One

  • Manufacturer/Model
    HP Pavilion m9515y
    CPU
    Phenom X4 9850
    Memory
    8 GB
    Graphics Card(s)
    Some Radeon Cheapie with 512 MB Ram
    Monitor(s) Displays
    CRT
    Screen Resolution
    1280x1024
    Hard Drives
    750 GB SATA 3G
    2 SIIG Superspeed docks w/WD Caviar Black Sata II or III
Back
Top