Scala:带有参数

时间:2017-01-10 18:27:57

标签: python scala

所以我在Scala中发送这个系统命令:

val command = "python other/evaluateAnswers.py 'chemistry earth' 'the chemistry of the world in champaign' 'the chemistry of the computer science world'"

命令。!!

这是我的python代码的简化版本:

def main(argv):
    # example run:
    print(argv)
    # do stuff here ... 

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

如果我直接在终端内运行:

daniel$ python other/evaluateAnswers.py 'chemistry earth' 'the chemistry of the world in champaign' 'the chemistry of the computer science world'

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

['chemistry earth', 'the chemistry of the world in champaign', 'the chemistry of the computer science world']

这是正确的。

如果我通过command.!!从scala运行此操作,我会在print(argv)的输出中获得以下内容:

["'chemistry", "earth'", "'the", 'chemistry', 'of', 'the', 'world', 'in', "champaign'", "'the", 'chemistry', 'of', 'the', 'computer', 'science', "world'"]

这是错误的分裂。

我出错的任何想法?

1 个答案:

答案 0 :(得分:2)

手动拆分我的scala命令就可以了:

val command = Seq("python", "other/evaluateAnswers.py", "'chemistry earth'", "'the chemistry of the world in champaign'", "'the chemistry of the computer science world'")
command.!!