python shell命令解析_在python中解析或运行docker shell命令

以下面的shinyproxy山药为例:proxy:

title: Open Analytics Shiny Proxy

logo-url: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png

landing-page: /

heartbeat-rate: 10000

heartbeat-timeout: 60000

port: 8080

authentication: simple

admin-groups: scientists

# Example: 'simple' authentication configuration

users:

- name: jack

password: password

groups: scientists

- name: jeff

password: password

groups: mathematicians

# Example: 'ldap' authentication configuration

ldap:

url: ldap://ldap.forumsys.com:389/dc=example,dc=com

user-dn-pattern: uid={0}

group-search-base:

group-search-filter: (uniqueMember={0})

manager-dn: cn=read-only-admin,dc=example,dc=com

manager-password: password

# Docker configuration

docker:

cert-path: /home/none

url: http://localhost:2375

port-range-start: 20000

specs:

- id: 01_hello

display-name: Hello Application

description: Application which demonstrates the basics of a Shiny app

container-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]

container-image: openanalytics/shinyproxy-demo

access-groups: [scientists, mathematicians]

- id: 06_tabsets

container-cmd: ["R", "-e", "shinyproxy::run_06_tabsets()"]

container-image: openanalytics/shinyproxy-demo

access-groups: scientists

logging:

file:

shinyproxy.log

如何将["R", "-e", "shinyproxy::run_06_tabsets()"]解析为普通的exec格式,或者直接运行此命令而不在python中进行解析?有空吗?在

编辑:

我想在subprocess中运行该命令,并在超时或运行Shiny app时发生错误后终止它:

MWE:

^{pr2}$

终端输出:>>> from subprocess import Popen, PIPE

... from threading import Timer

...

... cmd_from_yaml = ['R', '-e', 'shinyproxy::run_06_tabsets()']

... docker_cmd = "docker run -i {0} {1}".format(vol, img)

... docker_cmd = docker_cmd.split()

... docker_cmd.extend(cmd_from_yaml)

... timeout_sec = 10

... print("Running command: " + str(" ".join(docker_cmd)))

... proc = Popen(docker_cmd, stdout=PIPE, stderr=PIPE, shell=False)

...

... timer = Timer(timeout_sec, proc.kill)

... try:

... timer.start()

... stdout, stderr = proc.communicate()

... finally:

... timer.cancel()

...

... if stderr:

... proc.kill()

... raise Exception("Error: " + str(stderr))

...

Running command: docker run -i openanalytics/shinyproxy-demo R -e shinyproxy::run_06_tabsets()

Traceback (most recent call last):

File "", line 21, in

Exception: Error: b'Loading required package: shiny\n\nListening on http://0.0.0.0:3838\n'

注意,命令docker run -i openanalytics/shinyproxy-demo R -e "shinyproxy::run_06_tabsets()"会因为添加缺少的引号而起作用,但我在这个问题中的重点是,是否有任何方法可以自动执行此操作,而不会像docker compose中那样手动添加缺少的引号。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值