www.91084.com

GVKun编程网logo

Shell命令之将iOS的APP安装到模拟器中(shell命令安装apk)

8

如果您想了解Shell命令之将iOS的APP安装到模拟器中的相关知识,那么本文是一篇不可错过的文章,我们将对shell命令安装apk进行全面详尽的解释,并且为您提供关于adbshell命令查看app进

如果您想了解Shell命令之将iOS的APP安装到模拟器中的相关知识,那么本文是一篇不可错过的文章,我们将对shell命令安装apk进行全面详尽的解释,并且为您提供关于adb shell命令查看app进程并kill、adb shell命令查看并杀死app进程、Android Shell命令之dumpsys部分功能简介、C++实现模拟shell命令行(代码解析)的有价值的信息。

本文目录一览:

Shell命令之将iOS的APP安装到模拟器中(shell命令安装apk)

Shell命令之将iOS的APP安装到模拟器中(shell命令安装apk)

启动运行模拟器

xcrun instruments -w 'iPhone 6 Plus'

在已经启动好的模拟器中安装应用:

xcrun simctl install booted /Users/xiatian/Desktop/ios-app-bootstrap.app (这里要特别注意,是app,不是ipa 安装时需要提供的是APP的文件路径)

卸载APP的命令

xcrun simctl uninstall booted com.xiatian.bootstrap

卸载时需要写的是bundle identifier。

adb shell命令查看app进程并kill

adb shell命令查看app进程并kill

1.查看进程

adb shell ps|findstr package

 

分享图片

2.杀死进程

方法1:强制停止APP进程,不会清除APP进程在系统中产生的数据

adb shell am force-stop package

分享图片

执行该命令后没有输出,手机对应进程已被杀死。

方法2:停止APP进程,并且清除这个APP进程产生的所有数据,相当于reset

adb shell pm clear package

 

分享图片

执行该命令后输出success即表示命令执行成功,app进程被杀死,且会清楚所有数据,相当于卸载重装的效果,一般不建议使用。

adb shell命令查看并杀死app进程

adb shell命令查看并杀死app进程

1.查看进程

adb shell ps|findstr package

 

2.杀死进程

方法1:强制停止APP进程,不会清除APP进程在系统中产生的数据

adb shell am force-stop package

执行该命令后没有输出,手机对应进程已被杀死。

方法2:停止APP进程,并且清除这个APP进程产生的所有数据,相当于reset

adb shell pm clear package

 

执行该命令后输出success即表示命令执行成功,app进程被杀死,且会清楚所有数据,相当于卸载重装的效果,一般不建议使用。

 

Android Shell命令之dumpsys部分功能简介

Android Shell命令之dumpsys部分功能简介

adb简称 android debug bridge, 通过adb我们获得了查看android手机的另一个窗口。可以通过它看到一些内部的东西。

dumpsys则是其中一个很强大的工具。作用跟名字说的有点像,查看系统信息。

android下的每一个系统组件都有一个名字,如window, surfaceFinger, nfc, battery ... 所有这些服务都心照不宣的提供了一个 dump()的接口,供dumpsys命令调用。不过android有个奇葩的地方,每个手机出来的东西可能不一样,好多被那些厂商给改的面目全非。

先看一个dumpsys比较简单的应用

输入命令

$ adb shell dumpsys battery
Current Battery Service state:
  AC powered: false
  USB powered: true
  status: 5
  health: 2
  present: true
  level: 100
  scale: 100
  voltage:4195
  temperature: 305
  technology: Li-ion

看吧,直接把电池的各种参数都导出出来了。清晰的可以看到电池的温度是30.5摄氏度

如果需要拿到全部服务有哪些,可以使用命令 dumpsys | grep "DUMP OF SERVICE" 或者 adb shell service list

dumpsys 常用列表

下面我们就把常用的dumpsys服务一一列出来,可能很长很长

battery

$ adb shell dumpsys battery
Current Battery Service state:
  AC powered: false
  USB powered: true
  status: 5
  health: 2
  present: true
  level: 100
  scale: 100
  voltage:4195
  temperature: 305
  technology: Li-ion

wifi

adb shell dumpsys wifi

可以获取到当前连接的wifi名、搜索到的wifi列表、wifi强度等

power

adb shell dumpsys power
  • 可以获取到是否处于锁屏状态:mWakefulness=Asleep或者mScreenOn=false
  • 亮度值:mScreenBrightness=255
  • 屏幕休眠时间:Screen off timeout: 60000 ms

telephony.registry

adb shell dumpsys telephony.registry

可以获取到电话状态,例如

  • mCallState值为0,表示待机状态、1表示来电未接听状态、2表示电话占线状态
  • mCallForwarding=false #是否启用呼叫转移
  • mDataConnectionState=2 #0:无数据连接 1:正在创建数据连接 2:已连接
  • mDataConnectionPossible=true #是否有数据连接
  • mDataConnectionApn= #APN名称

其他,等我想到了再补充

参考资料

  • http://stackoverflow.com/questions/11201659/whats-the-android-adb-shell-dumpsys-tool-and-what-are-its-benefits
  • adb使用指南

C++实现模拟shell命令行(代码解析)

C++实现模拟shell命令行(代码解析)

一、解析

/**
 * 进行命令行解析:
 * 多个空格
 * 分割符:< > |
 * */
void parse(){
    std::string line;
    getline(std::cin, line);
    /** 解析字符串 */
    int len = line.size(), i=0;

    std::string tmp;
    std::vector<std::string> tmp_vc;
    while(i < line.size()){
        if(line[i] == '' ''){
            i++;
            continue;
        }
        if(line[i] == ''|'') {
            vc.push_back(tmp_vc);
            tmp = "";
            i++;
            continue;
        }
        int pos = line.find('' '', i);    // 获取下一个空格的位置
        tmp = line.substr(i, pos-i);    // 截取字符串
        tmp_vc.push_back(tmp);
        i = pos;
    }
    vc.push_back(tmp_vc);
}

二、执行命令函数

/** 执行命令子函数 */
void func(std::vector<std::string>& v){
    char *arr[10];
    pid_t pid;
    pid = fork();
    if(pid == -1){
        std::cout << "fork error" << std::endl;
        exit(1);
    }else if(pid ==0){
        for(int i=0; i<v.size(); ++i)
            arr[i] = (char *)v[i].c_str();
        arr[v.size()] = NULL;
        execvp(arr[0], arr);
    }else{
        wait(NULL);
    }
}

/** 执行命令
 * --------
 * 创建子进程执行
 * 当出现|需要创建多个子进程
 * 当出现> <则将内容写入文件或者命令行
 * */
void execCommnd(){
    for(int i=0; i<vc.size(); ++i){
        func(vc[i]);
    }
}

三、模拟shell

/** 获取当前所在目录 */
void getCurPwd(){
    std::string s = get_current_dir_name();
    int pos  = s.rfind(''/'');
    std::string tmp = s.substr(pos+1, s.length()-pos);
    std::cout << tmp << "]# ";
}

/** 获取当前用户名 */
void getIdname(){
    struct  passwd *pwd;
    pwd = getpwuid(getuid());
    std::cout << "["  <<pwd->pw_name << "@";
}

/** 获取当前主机名 */
void getHostName(){
    char buf_w[128];
    int hostname = gethostname(buf_w, sizeof(buf_w)); 
    std::cout << buf_w << " ";
    
}

/** 显示菜单 */
void showMenu(){
    getIdname();
    getHostName();
    getCurPwd();
}

四、完整代码

/*----------------------------------------------------------------------
	> File Name: shellDemo.cpp
	> Author: Jxiepc
	> Mail: Jxiepc
	> Created Time: Sun 19 Dec 2021 11:24:21 AM CST
----------------------------------------------------------------------*/

#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <pwd.h>
#include <wait.h>

/* 存储命令以及参数 */
std::vector<std::vector<std::string>> vc;

/**
 * 进行命令行解析:
 * 多个空格
 * 分割符:< > |
 * */
void parse(){
    std::string line;
    getline(std::cin, line);
    /** 解析字符串 */
    int len = line.size(), i=0;

    std::string tmp;
    std::vector<std::string> tmp_vc;
    while(i < line.size()){
        if(line[i] == '' ''){
            i++;
            continue;
        }
        if(line[i] == ''|'') {
            vc.push_back(tmp_vc);
            tmp = "";
            i++;
            continue;
        }
        int pos = line.find('' '', i);                // 获取下一个空格的位置
        tmp = line.substr(i, pos-i);    // 截取字符串
        tmp_vc.push_back(tmp);
        i = pos;
    }
    vc.push_back(tmp_vc);
}

/** 执行命令子函数 */
void func(std::vector<std::string>& v){
    char *arr[10];
    pid_t pid;
    pid = fork();
    if(pid == -1){
        std::cout << "fork error" << std::endl;
        exit(1);
    }else if(pid ==0){
        for(int i=0; i<v.size(); ++i)
            arr[i] = (char *)v[i].c_str();
        arr[v.size()] = NULL;
        execvp(arr[0], arr);
    }else{
        wait(NULL);
    }
}

/** 执行命令
 * --------
 * 创建子进程执行
 * 当出现|需要创建多个子进程
 * 当出现> <则将内容写入文件或者命令行
 * */
void execCommnd(){
    for(int i=0; i<vc.size(); ++i){
        func(vc[i]);
    }
}

/** 获取当前所在目录 */
void getCurPwd(){
    std::string s = get_current_dir_name();
    int pos  = s.rfind(''/'');
    std::string tmp = s.substr(pos+1, s.length()-pos);
    std::cout << tmp << "]# ";
}

/** 获取当前用户名 */
void getIdname(){
    struct  passwd *pwd;
    pwd = getpwuid(getuid());
    std::cout << "["  <<pwd->pw_name << "@";
}

/** 获取当前主机名 */
void getHostName(){
    char buf_w[128];
    int hostname = gethostname(buf_w, sizeof(buf_w)); 
    std::cout << buf_w << " ";
    
}

/** 显示菜单 */
void showMenu(){
    getIdname();
    getHostName();
    getCurPwd();
}

void test(){
    while(1){
        showMenu();
        parse();
        execCommnd();
    }
}

int main(int argc, char* argv[])
{
    test();
    return 0;
}

四、运行结果

到此这篇关于C++实现模拟shell命令行的文章就介绍到这了,更多相关C++ shell命令行内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

您可能感兴趣的文章:
  • C++执行shell命令的多种实现方法
  • C++实现希尔排序(ShellSort)
  • C++命令行解析包gflags的使用教程
  • 用C++实现一个命令行进度条的示例代码

今天关于Shell命令之将iOS的APP安装到模拟器中shell命令安装apk的讲解已经结束,谢谢您的阅读,如果想了解更多关于adb shell命令查看app进程并kill、adb shell命令查看并杀死app进程、Android Shell命令之dumpsys部分功能简介、C++实现模拟shell命令行(代码解析)的相关知识,请在本站搜索。

本文标签: