首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将参数传递给shell命令

将参数传递给shell命令
EN

Stack Overflow用户
提问于 2021-07-25 23:09:22
回答 1查看 57关注 0票数 0

我有一个在python脚本中执行的shell脚本,我想将两个变量作为参数传递给该脚本。我使用了$ sign,但它不起作用。这是shell脚本:

代码语言:javascript
复制
path='/home/ranim/Documents/mmdet/media/Page_00287_jpg.rf.6a823c5ce3894f223a0e8f4ec20b11b2/article1'
save='/home/ranim/Documents/mmdet/media/Page_00287_jpg.rf.6a823c5ce3894f223a0e8f4ec20b11b2/article1/annotations.json'
call('python "/home/ranim/Documents/mmdet/mmdetection/tools/test.py" \
"/home/ranim/Documents/mmdet/models/second_model_conf.py" \
"/home/ranim/Documents/mmdet/models/second_model_checkpoint.pth" \
--cfg-options data.test.ann_file=$save \
data.test.img_prefix=$path \
--format-only \
--options "jsonfile_prefix=path"', shell=True)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-25 23:27:57

我猜字符串插值可以用来将Python变量传递给call命令的args。例如,如果使用fstring,代码将如下所示:

代码语言:javascript
复制
path='/home/ranim/Documents/mmdet/media/Page_00287_jpg.rf.6a823c5ce3894f223a0e8f4ec20b11b2/article1'
save='/home/ranim/Documents/mmdet/media/Page_00287_jpg.rf.6a823c5ce3894f223a0e8f4ec20b11b2/article1/annotations.json'
call(f'python "/home/ranim/Documents/mmdet/mmdetection/tools/test.py" \
"/home/ranim/Documents/mmdet/models/second_model_conf.py" \
"/home/ranim/Documents/mmdet/models/second_model_checkpoint.pth" \
--cfg-options data.test.ann_file={save} \
data.test.img_prefix={path} \
--format-only \
--options "jsonfile_prefix=path"', shell=True)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68519873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档