<Android> 使用Runtime运行linux命令

public boolean execute(String cmd) {
    String[] command = new String[] { "sh", "-c", cmd };
    Runtime runtime = Runtime.getRuntime();
    try {
        Process process = runtime.exec(command);
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        StringBuffer pathBuf = new StringBuffer();

        while ((line = in.readLine()) != null) {
            pathBuf.append(line);
        }
        in.close();

    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

其中:

cmd命令是linux命令, 如"ls"等


Python 3.12.9 (main, Feb 4 2025, 22:30:28) [Clang 18.0.3 (https://android.googlesource.com/toolchain/llvm-project d8003a456 on linux Type "help", "copyright", "credits" or "license" for more information. >>> import akshare as ak Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/akshare/__init__.py", line 4642, in <module> from akshare.stock_feature.stock_a_pe_and_pb import ( File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/akshare/stock_feature/stock_a_pe_and_pb.py", line 320, in <module> js_functions = py_mini_racer.MiniRacer() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/py_mini_racer/py_mini_racer.py", line 178, in __init__ self.__class__.ext = _build_ext_handle() ^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/py_mini_racer/py_mini_racer.py", line 125, in _build_ext_handle raise RuntimeError("Native library not available at {}".format(EXTENSION_PATH)) RuntimeError: Native library not available at /data/data/com.termux/files/usr/lib/python3.12/site-packages/py_mini_racer/libmini_racer.glibc.so >>> >>> # 使用无JavaScript依赖的接口 >>> data = ak.stock_zh_a_spot() # 实时行情接口 Exception ignored in: <function MiniRacer.__del__ at 0x7684a76520> Traceback (most recent call last): File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/py_mini_racer/py_mini_racer.py", line 315, in __del__ self.ext.mr_free_context(getattr(self, "ctx", None)) ^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'mr_free_context' Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'ak' is not defined >>> print(data[data['代码'] == '000001']) # 筛选上证 指数 Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'data' is not defined >>> >>> # 历史数据替代方案 >>> data = ak.stock_zh_a_daily(symbol="sh000001", adjust="hfq") Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'ak' is not defined
最新发布
03-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值