python调用linux命令---神算子

本文介绍两种使用Python执行Linux命令的方法。第一种利用os模块的system函数执行命令但不返回结果;第二种通过popen读取命令输出,适用于需要处理命令返回值的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



第一种方式,没有返回结果在脚本中

import os
os.system("在此执行任何linux命令")
例如:os.system("ls")



第二种方式:在脚本中可以接收返回值
import os
ddd = os.popen('ps -ef | grep java | wc -l').read()
if ddd==0:
        print aaa
else:
        print ddd



第一种方式,没有返回结果在脚本中

import os
os.system("在此执行任何linux命令")
例如:os.system("ls")



第二种方式:在脚本中可以接收返回值
import os
ddd = os.popen('ps -ef | grep java | wc -l').read()
if ddd==0:
        print aaa
else:
        print ddd



``` (Pdb) n > /models/z50051264/bitsandbytes-pangu/examples/inference/nf4_save.py(3)<module>() -> import torch, torch_npu (Pdb) n DrvMngGetConsoleLogLevel failed. (g_conLogLevel=3) [ERROR] ATRACE(574,python):2025-07-30-07:10:48.716.910 [trace_driver_api.c:56](tid:574) get platform info failed, drvErr=87. [EVENT] PROFILING(574,python):2025-07-30-07:10:48.720.578 [msprof_callback_impl.cpp:358] >>> (tid:574) Started to register profiling ctrl callback. [EVENT] PROFILING(574,python):2025-07-30-07:10:48.720.832 [msprof_callback_impl.cpp:365] >>> (tid:574) Started to register profiling hash id callback. [INFO] PROFILING(574,python):2025-07-30-07:10:48.720.909 [prof_atls_plugin.cpp:117] (tid:574) RegisterProfileCallback, callback type is 7 [EVENT] PROFILING(574,python):2025-07-30-07:10:48.720.973 [msprof_callback_impl.cpp:372] >>> (tid:574) Started to register profiling enable host freq callback. [INFO] PROFILING(574,python):2025-07-30-07:10:48.721.036 [prof_atls_plugin.cpp:117] (tid:574) RegisterProfileCallback, callback type is 8 [INFO] RUNTIME(574,python):2025-07-30-07:10:48.724.717 [task_fail_callback_data_manager.cc:58] 574 TaskFailCallBackManager: Constructor. [INFO] HCCL(574,python):2025-07-30-07:10:48.791.006 [adapter_rts.cc:2720] [574][adapter_rts.cc][CallBackInitRts] g_deviceType [6] g_deviceLogicId [-1] g_devicePhyId [-1] [INFO] PROFILING(574,python):2025-07-30-07:10:49.549.198 [prof_atls_plugin.cpp:210] (tid:574) Module[0] register callback of ctrl handle. [INFO] PROFILING(574,python):2025-07-30-07:10:49.780.922 [prof_atls_plugin.cpp:210] (tid:574) Module[61] register callback of ctrl handle. > /models/z50051264/bitsandbytes-pangu/examples/inference/nf4_save.py(4)<module>() -> from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig ``` 什么原因???
最新发布
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值