
Gửi bởi
hth2813
Gọi ABD thì có thể gọi được bạn ạ, nhưng vấn đề là mình muốn lấy cái tên thiết bị của nó sau khi gõ adb devices ấy [IMG]images/smilies/17.gif[/IMG]
Thì dùng pipe để lấy kết quả trả về của lệnh.
Cái này thì còn tùy vào sử dụng HDH nào. Trên *nix thì dùng hàm pipe() hoặc popen().
------------------------------------------------------------------------------------------------------
Code chạy trên Linux, đã test:
Mã:
/* * ===================================================================================== * * Filename: list-adb-devices.cc * * Description: * * Version: 1.0 * Created: 06/12/2014 03:47:09 PM * Revision: none * Compiler: gcc * * Author: BOSS14420 (), firefoxlinux at gmail dot com * Organization: * * ===================================================================================== */ #include <cctype>#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/wait.h> int main(){ int fds[2]; pipe(fds); int pid = fork(); if (pid == 0) { // child process close(1); dup(fds[1]); close(fds[0]); close(fds[1]); int status = execlp("adb", "adb", "devices", NULL); //int status = execlp("adb", "devices", NULL); if (status == -1) { perror("execlp:"); } } else if (pid > 0) { // parrent process close(fds[1]); puts("Danh sach thiet bi:"); char buffer[81]; int c, id = 0; FILE *f = fdopen(fds[0], "r"); while ( (c = getc(f)) != EOF ) { if (c == '
') { char *pb = buffer; do { *pb++ = c = getc(f); } while ( std::isalnum(c) ); *(pb-1) = '\0'; if (buffer[0] && buffer[0] != ' ') { fprintf(stdout, "%2d. %s
", ++id, buffer); buffer[0] = '\0'; } } } waitpid(pid, NULL, 0); } return 0;}
NGUỒN SỈ ÁO KHOÁC DENIM NỮ TPHCM CHẤT LƯỢNG CAO Bạn muốn nhập sỉ áo khoác denim nữ để bắt đầu việc buôn bán Online phong cách nhưng lại chưa có kinh nghiệm, muốn sắm xưởng sỉ xống áo vừa có thể giải...
Xưởng sỉ áo khoác jeans denim giá...