-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.c
More file actions
83 lines (80 loc) · 2.6 KB
/
Copy pathrun.c
File metadata and controls
83 lines (80 loc) · 2.6 KB
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
78
79
80
81
82
83
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char fileExt[9];
char dirve[9];
char fileNameWithoutExt[99];
char filePath[99];
char fDir[128] = {};
char comText[255];
char comTextFinall[255];
int MAXPATH = 1024;
char buffer[MAXPATH];
_getcwd(buffer, MAXPATH);
_splitpath(argv[1], dirve, filePath, fileNameWithoutExt, fileExt);
strcat(fDir, dirve);
strcat(fDir, filePath);
if (*fileExt != 0)
{
/*
printf("文件基本名:%s\n", fileNameWithoutExt);
printf("文件类型是:%s\n", fileExt);
printf("文件目录是:%s\n", fDir);
*/
printf("文件路径:%s\n", argv[1]);
//*/
if (!strcmp(fileExt, ".txt"))
{
goto Unmatched;
}
if (!strcmp(fileExt, ".bat") || !strcmp(fileExt, ".cmd"))
{
sprintf(comText, "\"%s\"", argv[1]);
}
if (!strcmp(fileExt, ".py") || !strcmp(fileExt, ".pyw"))
{
sprintf(comText, "\"%s\"", argv[1]);
}
if (!strcmp(fileExt, ".ui"))
{
sprintf(comText, "pyuic5 \"%s\" -o \"%s.py\"", argv[1], fileNameWithoutExt);
}
if (!strcmp(fileExt, ".c"))
{
sprintf(comText, "gcc -fexec-charset=gbk \"%s\" -o \"%s\" && \"%s.exe\"", argv[1], fileNameWithoutExt, fileNameWithoutExt);
}
if (!strcmp(fileExt, ".cpp"))
{
sprintf(comText, "g++ -fexec-charset=gbk \"%s\" -o \"%s\" && \"%s.exe\"", argv[1], fileNameWithoutExt, fileNameWithoutExt);
}
if (!strcmp(fileExt, ".cs"))
{
sprintf(comText, "csc \"%s\" && \"%s\"", argv[1], fileNameWithoutExt);
}
if (!strcmp(fileExt, ".java"))
{
sprintf(comText, "javac -encoding UTF-8 \"%s\" && java \"%s\"", argv[1], fileNameWithoutExt);
}
if (!strcmp(fileExt, ".csproj"))
{
sprintf(comText, "dotnet run --project \"%s\"", argv[1]);
}
}
else
{
printf(" ERROR:未匹配的当前文件类型,请检查输入!\n");
strcpy(fDir, buffer);
Unmatched:
sprintf(comText, "echo %s", buffer);
}
sprintf(comTextFinall, "cd /d \"%s\" && %s", fDir, comText);
printf("当前路径:%s\n", fDir);
printf("运行命令:%s\n", comText);
printf("------------------------------------------------------------------\n");
system(comTextFinall);
printf("------------------------------------------------------------------\n");
system("pause");
return 0;
}