1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| #include <stdio.h> #include <string.h> #include <stdlib.h> #include <windows.h>
int GBK2UTF8(char *szGbk,char *szUtf8,int Len) { int n = MultiByteToWideChar(CP_ACP,0,szGbk,-1,NULL,0); WCHAR test[sizeof(WCHAR) * n]; WCHAR *str1 = test; MultiByteToWideChar(CP_ACP, 0, szGbk, -1, str1, n );
n = WideCharToMultiByte(CP_UTF8, 0, str1, -1, NULL, 0, NULL, NULL); if (n > Len) { return -1; } WideCharToMultiByte(CP_UTF8, 0, str1, -1, szUtf8, n, NULL, NULL); str1 = NULL; return 0; }
int main(int argc, char **argv) { char canshu[1000]; canshu[0]=0; for (int i = 1; i < argc; ++i) { strcat(canshu,argv[i]); strcat(canshu," "); } strcat(canshu,">%tmp%\\output.txt 2>&1"); int fanhui = system(canshu); FILE *fp; char OutPath[100]; GetTempPath(100, OutPath); strcat(OutPath,"\\output.txt"); fp=fopen(OutPath,"r"); char ch; char hang[1000]; int i = 0; while((ch=fgetc(fp))!=EOF) { hang[i++]=ch; if (ch=='\n') { hang[i++]=0; if (hang[1]==':' && hang[2]=='\\') { GBK2UTF8(hang,canshu,1000); printf("%s", canshu); }else { printf("%s",hang); } i = 0; } } fclose(fp); return fanhui; }
|