代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
转发输入流至多个输出流的程序
作者:
DDT
/ 发布于
2013/1/8
/
453
/* * TEE.C - external command. * * clone from 4nt tee command * * 01 Sep 1999 - Paolo Pantaleo <paolopan@freemail.it> * started * * */ #include <windows.h> #include <tchar.h> #include <stdio.h> #include <malloc.h> #define TEE_BUFFER_SIZE 8192 /*these are function that emulate the ones used in cmd*/ /*many of them are just copied in this file from their original location*/ VOID ConOutPuts (LPTSTR szText) { DWORD dwWritten; WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szText, _tcslen(szText), &dwWritten, NULL); WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), _T("\n"), 1, &dwWritten, NULL); } VOID ConErrPrintf (LPTSTR szFormat, ...) { DWORD dwWritten; TCHAR szOut[4096]; va_list arg_ptr; va_start (arg_ptr, szFormat); _vstprintf (szOut, szFormat, arg_ptr); va_end (arg_ptr); WriteFile (GetStdHandle (STD_ERROR_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL); } VOID error_sfile_not_found (LPTSTR f) { ConErrPrintf (_T("Error opening file") _T(" - %s\n"), f); } VOID ConErrPuts (LPTSTR szText) { ConErrPrintf(_T("%s\n"),szText ); } INT main (int argc,char **p) { /*reading/writing buffer*/ TCHAR buff[TEE_BUFFER_SIZE]; /*handle for file and console*/ HANDLE hConsoleIn,hConsoleOut; /*bytes written by WriteFile and ReadFile*/ DWORD dwRead,dwWritten; BOOL bRet,bAppend=FALSE; /*command line parsing stuff*/ LPTSTR tmp; INT i; BOOL bQuote; /*file list implementation*/ LPTSTR *files; INT iFileCounter=0; HANDLE *hFile; /*used to remove '"' (if any)*/ INT add; DWORD dw; if (argc < 2) return 1; if (_tcsncmp (p[1], _T("/?"), 2) == 0) { ConOutPuts (_T("Copy standard input to both standard output and a file.\n" "\n" "TEE [/A] file...\n" "\n" " file One or more files that will receive output.\n" " /A Append output to files.\n")); return 0; } files = malloc(sizeof(LPTSTR)*argc); hFile = malloc(sizeof(HANDLE)*argc); hConsoleIn=GetStdHandle(STD_INPUT_HANDLE); hConsoleOut=GetStdHandle(STD_OUTPUT_HANDLE); /*parse command line for /a and file name(s)*/ for(i=1;i <argc;i++) { bQuote=FALSE; add=0; if(_tcsnicmp(p[i],_T("/a"),2) == 0) { bAppend = TRUE; continue; } /*remove quote if any*/ if (p[i][0] == _T('"')) { tmp = _tcschr (p[i]+1, _T('"')); if (tmp != 0) { add = 1; *tmp= _T('\0'); } } /*add filename to array of filename*/ /* if( iFileCounter >= sizeof(files) / sizeof(*files) ) { ConErrPrintf("too many files, maximum is %d\n",sizeof(files) / sizeof(*files)); return 1; } */ files[iFileCounter++]= p[i]+add; } /*open file(s)*/ for(i=0;i<iFileCounter;i++) { //l=0; hFile[i] = CreateFile(files[i],GENERIC_WRITE, 0,NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL); if (hFile[i] == INVALID_HANDLE_VALUE) { error_sfile_not_found (files[i]); for(i=0;i<iFileCounter;i++) CloseHandle (hFile[i]); free (files); free (hFile); return 1; } /*set append mode*/ if (bAppend) { if (GetFileType (hFile[i]) == FILE_TYPE_DISK) { dw = SetFilePointer (hFile[i],0,NULL,FILE_END); if (dw == 0xFFFFFFFF) { ConErrPrintf(_T("error moving to end of file %s"),files[i]); for(i=0;i<iFileCounter;i++) CloseHandle (hFile[i]); free (files); free (hFile); return 1; } ConErrPrintf(_T("SetFilePointer() = %d\n"),dw); } } } /*read and write*/ do { bRet = ReadFile(hConsoleIn,buff,sizeof(buff),&dwRead,NULL); if (dwRead>0 && bRet) { for(i=0;i<iFileCounter;i++) WriteFile(hFile[i],buff,dwRead,&dwWritten,NULL); WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL); } } while(dwRead>0 && bRet); for(i=0;i<iFileCounter;i++) CloseHandle (hFile[i]); free (files); free (hFile); return 0; } /* EOF */
试试其它关键字
输出流
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
DDT
贡献的其它代码
(
160
)
.
Oracle统计表的数据行和数据块信息
.
html标签闭合检测与修复
.
Powershell日期计算
.
Powershell的Base64编解码
.
Powershell并行循环
.
Powershell目录中搜索文本
.
Powershell枚举远程机器上的本地权限组
.
VBScript解析csv文件
.
快速排序之Powershell
.
批处理输出格式化时间字符串
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3