您当前的位置: 首页 >  c++

鱼儿-1226

暂无认证

  • 0浏览

    0关注

    1100博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++调用bat并实现传参

鱼儿-1226 发布时间:2021-11-04 18:08:11 ,浏览量:0

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;

    }

}   

关注
打赏
1604459285
查看更多评论
立即登录/注册

微信扫码登录

0.0478s