1.设置环境变量,这一类为路径
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void
bat(
const
string& sDirC,
const
string& sDirD)
{
char
Ddir[256];
Ddir[0] = 0;
sprintf_s(Ddir,
"DDIR=%s%s"
, (
char
*)sDirD.data(),
"\\"
);
_putenv(Ddir);
//将地址设置到当前环境中
char
Cdir[256];
Cdir[0] = 0;
sprintf_s(Cdir,
"CDIR=%s%s"
, (
char
*)sDirC.data(),
"\\"
);
_putenv(Cdir);
system
(
"..\\..\\Bin\\x64\\copy.bat"
);
//调用bat 推荐下面那种
/*if (WinExec("..\\..\\Bin\\x64\\copy.bat", SW_HIDE) < 32)
{
AfxMessageBox(L" 无法调用 ..\\..\\Bin\\x64\\copy.bat", NULL, MB_OK);
return false;
}*/
}
Bat
1
2
3
4
5
6
set
tmpDir=%DDIR%
md %tmpDir%
if
not exist %tmpDir% (
set
tmpDir=%CDIR%
md %tmpDir%
)
2.直接传值
bat默认只能获取到1-9个参数,分别用%1 %2 ... %9引用,如果传给bat的参数大于9个,就要用shift。
1
2
3
4
5
6
7
8
9
10
11
12
13
void
bat(
const
CString& csVersion)
{
char
packCmd[256];
sprintf_s(packCmd,
"%s%s"
,
"..\\..\\Bin\\x64\\pack.bat "
, T2A(csVersion));
//system(packCmd);
if
(WinExec(packCmd, SW_HIDE) < 32)
{
AfxMessageBox(L
"..\\..\\Bin\\x64\\pack.bat "
, NULL, MB_OK);
return
false
;
}
}