C++中调用ADB实现pull命令获取手机文件,获取文件出错 10C

以下代码不能获取手机目录下全部文件,只能得到一部分文件,但是直接用ADB可以正常获取全部文,求解释

#define ADB_PATH _T("D:\\ADB\\adb.exe")
char pResult[20000];
    int iResultSize=20000;
    if(ExecuteCommand(_T("adb pull /storage/emulated/0/MIUI/backup/AllBackup/ C:\\Users\\guojy2\\Desktop\\pre"),pResult,iResultSize))
    {
        AfxMessageBox(_T("true1"));
        KillProcess(sExeName);
    }

ExecuteCommand函数:

bool ExecuteCommand(CString strCommand, char *pResult, int iResultSize)

{

    const int PIPE_BUFFER_SIZE = 1024;

    HANDLE hReadPipe;

    HANDLE hWritePipe;

    HANDLE hReadPipecmd;

    HANDLE hWritePipecmd;



    STARTUPINFO          adbProcStartup;

    SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES),NULL, TRUE };



    BOOL bResult = CreatePipe(&hReadPipe, &hWritePipe ,&sa, PIPE_BUFFER_SIZE);

    if( bResult == 0 )

        return 0;


    bResult = CreatePipe(&hReadPipecmd, &hWritePipecmd ,&sa, PIPE_BUFFER_SIZE);

    if( bResult == 0 )

        return 0;


    PROCESS_INFORMATION  adbProcInfo;

    memset(&adbProcInfo, 0, sizeof(PROCESS_INFORMATION));

    memset(&adbProcStartup, 0, sizeof(STARTUPINFO));



    adbProcStartup.cb          = sizeof(STARTUPINFO);

    adbProcStartup.dwFlags     = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;

    adbProcStartup.hStdOutput  = hWritePipe;  

    adbProcStartup.hStdInput   = hReadPipecmd;

    adbProcStartup.wShowWindow = SW_HIDE;



    if(CreateProcess(ADB_PATH, (LPWSTR)(LPCWSTR)strCommand, NULL, NULL, TRUE, 0, NULL, NULL, &adbProcStartup, &adbProcInfo)) //startup adb.exe 

    {                        

        DWORD dwByteRead = 0;



        ReadFile(hReadPipe, pResult, iResultSize, &dwByteRead, NULL);  

    }

    else

    {

        return false;

    }



    CloseHandle(hReadPipe);

    CloseHandle(hReadPipecmd);



    return true;

}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐