首页 > 解决方案 > 如何在epicbox中提供超过1个输入参数

问题描述

我正在尝试使用epicbox来运行 python 代码。我面临两个问题。这是我的代码:

import epicbox
import pprint

untrusted_code = b"""
a = input()
print(a)
b = input()
print(b)"""

epicbox.configure(
    profiles=[
        epicbox.Profile('python', 'python')
    ]
)
files = [{'name': 'main.py', 'content': untrusted_code}]
limits = {'cputime': 1, 'memory': 64}
result = epicbox.run('python', 'python main.py', files=files, limits=limits, stdin="12 19")
pprint.pprint(result)

首先,我不确定如何在标准输入中放置超过 1 个输入参数,其次,它在输出中给了我以下错误:

{
 'duration': 0.098507,
 'exit_code': 1,
 'oom_killed': False,
 'stderr': b'Traceback (most recent call last):\n  File "/sandbox/main.py", li'
           b'ne 4, in <module>\n    b = input()\nEOFError: EOF when reading a l'
           b'ine\n',
 'stdout': b'12 19\n',
 'timeout': False
}

标签: pythonpython-3.xdocker

解决方案


我想到了。我需要\n在标准输入参数之间放置:

epicbox.run('python', 'python main.py', files=files, limits=limits, stdin='12\n13')

推荐阅读