• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            CreateProcess+Pipe 交互運行命令

            BOOL CNeowayAndroidCheckToolView::PipeSendCmd(const HANDLE& handle,LPCTSTR cmd)
            {
                CString _cmd(cmd);
                BOOL bRet;
                DWORD dwWrited;

                _cmd.Append(
            "\r\n");    
                
            return WriteFile(handle,_cmd,_cmd.GetLength(),&dwWrited,NULL);
            }
            BOOL CNeowayAndroidCheckToolView::PipeRead(
            const HANDLE& handle,CString& result,DWORD dwMilliseconds)
            {
                BOOL bRet 
            = FALSE;
                CHAR buffer[
            4100];
                DWORD dwReaded;

                result.Empty();
                
            while(1)
                {
                    Sleep(dwMilliseconds);
                    bRet 
            = PeekNamedPipe(handle,buffer,1,&dwReaded,NULL,NULL);
                    
            if (!bRet) goto _flag_exit;
                    
            if (dwReaded>0)
                    {
                        bRet 
            = ReadFile(handle, buffer,4096&dwReaded, NULL);
                        
            if (!bRet) goto _flag_exit;
                        buffer[dwReaded] 
            = '\0';
                        result 
            += buffer;
                    }
            else {
                        
            break;
                    }
                }
            _flag_exit:
                
            return bRet;
            }
            BOOL CNeowayAndroidCheckToolView::TestGpio()
            {
                CString init_cmd 
            = Path::Combine( Path::GetAppDirectory(),"adb.exe shell");
                
            //CString init_cmd = "cmd.exe";
                CString cmd;
                CString result;
                DWORD exit_code 
            = -1;
                STARTUPINFO si;
                PROCESS_INFORMATION pi;
                HANDLE hStdOutRead
            =NULL, hStdOutPipe=NULL;
                HANDLE hStdInWrite
            =NULL, hStdInPipe=NULL;
                SECURITY_ATTRIBUTES saRead,saWrite;
                BOOL bRet;
                BOOL bSucceed;    
                DWORD dwReaded;
                std::vector
            <CString> lines;

                saRead.nLength 
            = sizeof(SECURITY_ATTRIBUTES);
                saRead.bInheritHandle 
            = TRUE;
                saRead.lpSecurityDescriptor 
            = NULL;
                saWrite 
            = saRead;

                bRet 
            = CreatePipe(&hStdOutRead, &hStdOutPipe, &saRead, 4096);
                
            if (!bRet)
                    
            goto _flag_exit;
                bRet 
            = CreatePipe(&hStdInPipe, &hStdInWrite, &saWrite, 4096);
                
            if (!bRet)
                    
            goto _flag_exit;

                memset(
            &si, 0sizeof(si));
                si.cb 
            = sizeof(si);
                si.dwFlags 
            = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
                si.wShowWindow 
            = SW_HIDE;
                si.hStdOutput 
            = hStdOutPipe;
                si.hStdInput  
            = hStdInPipe;

                bRet 
            = CreateProcess(NULL, (LPSTR)(LPCTSTR)init_cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
                
            if (!bRet) goto _flag_exit;
                    

                CloseHandle(hStdOutPipe);hStdOutPipe 
            = NULL;
                CloseHandle(hStdInPipe);hStdInPipe 
            = NULL;

                bRet 
            = PipeRead(hStdOutRead,result,50);
                
            if (!bRet) goto _flag_exit;

                PipeSendCmd(hStdInWrite,
            "cd sys/gpio_test");
                
            if (!bRet) goto _exit_adb;

                bRet 
            = PipeRead(hStdOutRead,result,50);
                
            if (!bRet) goto _exit_adb;

                PipeSendCmd(hStdInWrite,
            "echo \"1\" > start");
                
            if (!bRet) goto _exit_adb;

                bRet 
            = PipeRead(hStdOutRead,result,50);
                
            if (!bRet) goto _exit_adb;

                PipeSendCmd(hStdInWrite,
            "cat result");
                
            if (!bRet) goto _exit_adb;

                bRet 
            = PipeRead(hStdOutRead,result,50);
                
            if (!bRet) goto _exit_adb;

                bRet 
            = (result.Find("OK")>=0);
            _exit_adb:
                
            if (!PipeSendCmd(hStdInWrite,"exit")) {
                    bRet 
            = FALSE; goto _flag_exit;
                }

                WaitForSingleObject( pi.hProcess, 
            5000);

                
            if (!GetExitCodeProcess(pi.hProcess, &exit_code)) {
                    bRet 
            = FALSE; goto _flag_exit;
                }
                bRet 
            = bRet && (exit_code==0);
            _flag_exit:
                
            if  (hStdOutRead!=NULL)
                    CloseHandle(hStdOutRead);
                
            if  (hStdOutPipe!=NULL)
                    CloseHandle(hStdOutPipe);
                
            if  (hStdInWrite!=NULL)
                    CloseHandle(hStdInWrite);
                
            if  (hStdInPipe!=NULL)
                    CloseHandle(hStdInPipe);
                
            return bRet;
            }

            posted on 2016-05-27 17:13 天下 閱讀(1632) 評論(0)  編輯 收藏 引用 所屬分類: Win32

            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            亚洲精品无码久久久| 久久99国产乱子伦精品免费| 久久久久亚洲精品天堂久久久久久 | 国产精品免费久久久久久久久| 久久久久久久久久免免费精品| 久久人人爽人人爽人人爽| 香蕉久久av一区二区三区| 91久久香蕉国产熟女线看| 中文字幕精品久久| 国产精品久久久久影院色| 亚洲?V乱码久久精品蜜桃 | 国产99久久精品一区二区| 国产99久久九九精品无码| 国产69精品久久久久久人妻精品| 丁香狠狠色婷婷久久综合| 国产一区二区三区久久| 婷婷综合久久狠狠色99h| 亚洲国产婷婷香蕉久久久久久| 国内精品伊人久久久久| 亚洲国产精品无码久久久蜜芽| 久久综合视频网站| 久久93精品国产91久久综合| 久久久久亚洲av无码专区| 久久久久久久免费视频| 国产女人aaa级久久久级| 久久福利青草精品资源站| 久久av无码专区亚洲av桃花岛| 久久经典免费视频| 热久久视久久精品18| 亚洲精品无码久久久久AV麻豆| 久久影视综合亚洲| 欧洲国产伦久久久久久久| 久久久久国产视频电影| 国产精品成人99久久久久| 国产精品久久久天天影视香蕉| 91久久精品国产成人久久| 久久精品嫩草影院| 久久激情五月丁香伊人| 久久午夜福利电影| 久久婷婷人人澡人人爽人人爱| 99久久99久久精品国产片果冻|