首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Scala:带参数的python脚本的系统命令

Scala:带参数的python脚本的系统命令
EN

Stack Overflow用户
提问于 2017-01-11 02:27:57
回答 1查看 361关注 0票数 3

因此,我在Scala中发送以下系统命令:

代码语言:javascript
复制
val command = "python other/evaluateAnswers.py 'chemistry earth' 'the chemistry of the world in champaign' 'the chemistry of the computer science world'"

命令。!!

以下是我的python代码的简化版本:

代码语言:javascript
复制
def main(argv):
    # example run:
    print(argv)
    # do stuff here ... 

if __name__ == '__main__':
    main(sys.argv[1:])

如果我直接在终端内部运行这个命令:

代码语言:javascript
复制
daniel$ python other/evaluateAnswers.py 'chemistry earth' 'the chemistry of the world in champaign' 'the chemistry of the computer science world'

下面是我的python代码中print(argv)的结果:

代码语言:javascript
复制
['chemistry earth', 'the chemistry of the world in champaign', 'the chemistry of the computer science world']

这是正确的。

但是,如果我通过command.!!在scala中运行这个命令,我会在print(argv)的输出中得到以下内容:

代码语言:javascript
复制
["'chemistry", "earth'", "'the", 'chemistry', 'of', 'the', 'world', 'in', "champaign'", "'the", 'chemistry', 'of', 'the', 'computer', 'science', "world'"]

这是不正确的拆分。

你知道我哪里错了吗?

EN

回答 1

Stack Overflow用户

发布于 2017-01-11 02:50:29

手动分割我的scala命令做到了这一点:

代码语言:javascript
复制
val command = Seq("python", "other/evaluateAnswers.py", "'chemistry earth'", "'the chemistry of the world in champaign'", "'the chemistry of the computer science world'")
command.!!
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41575841

复制
相关文章

相似问题

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