【发布时间】:2011-09-20 01:05:10
【问题描述】:
当我在 R 中执行脚本时,它是:
$ R --vanilla --args test_matrix.csv < hierarchical_clustering.R > out.txt
在 Python 中,如果我使用它就可以工作:
process = subprocess.call("R --vanilla --args "+output_filename+"_DM_Instances_R.csv < /home/kevin/AV-labels/Results/R/hierarchical_clustering.R > "+output_filename+"_out.txt", shell=True)
但是这个方法不提供process.wait()函数。
所以,我想用subprocess.Popen,我试过了:
process = subprocess.Popen(['R', '--vanilla', '--args', "\'"+output_filename+"_DM_Instances_R.csv\'", '<', '/home/kevin/AV-labels/Results/R/hierarchical_clustering.R'])
但它不起作用,Python 只是打开了 R 但没有执行我的脚本。
【问题讨论】:
-
你试过shell=True吗,即:subprocess.Popen(['R', '--vanilla', '--args', "\'"+output_filename+"_DM_Instances_R.csv\ '", '
-
它说:致命错误:你必须指定'--save','--no-save'或'--vanilla'但是'--vanilla'在那里......请帮助!!谢谢!!
-
根据“R --help”,“--args”参数的意思是“跳过命令行的其余部分”。这可能不是你的意思。你有可以向我们展示在 shell 中工作的命令行吗?
-
我的意思是......当我在 R 中运行我的脚本时,它与 $ R --vanilla --args test_matrix.csv
out.txt 一起工作此外,当我使用子进程时.call 在 python 中,它也可以工作......但我需要 subprocess.Popen 以便我可以使用 wait() 函数。
标签: python r subprocess os.system