我想在python 2.7脚本中运行LIWC(安装在我的Mac中)。
我一直在阅读关于subprocess(popen和check_output似乎是要走的路),但我没有得到以下语法:
这是我的第一个子进程方法,这可能吗? 我很欣赏这些建议。
修改
这是最接近实施解决方案(仍然不起作用):
我可以打开该应用程序。
subprocess.call(['open', '/file.app'])
但无法使其处理输入文件并获得输出文件。
subprocess.Popen(['/file.app', '-input', 'input.txt', '-output', 'output.txt'])
此代码没有任何内容。
编辑2
在阅读了几十篇文章之后,我仍然对解决方案的语法感到困惑。
关注How do I pipe a subprocess call to a text file?
我出来了这段代码:
g = open('in_file.txt', 'rb', 0)
f = open('out_file.txt', 'wb')
subprocess.call(['open', "file.app"] stdin=g, stdout=f)
输出文件为空。
编辑3
关注http://www.cplusplus.com/forum/unices/40680/
当我在终端上运行以下shell脚本时:
cat input.txt | /Path/LIWC > output.txt
输出txt文件为空。
编辑4
当我跑步时:
subprocess.check_call(['/PATH/LIWC', 'PATH/input.txt', 'PATH/output.txt'])
它打开LIWC,不创建输出文件并冻结。
编辑5
当我跑步时:
subprocess.call(['/PATH/LIWC', 'PATH/input.txt', 'PATH/output.txt'])
它运行LIWC,创建一个空的output.txt文件并冻结(该过程不会结束)。
答案 0 :(得分:0)
在'open'
中使用subprocess.call(['open', "file.app"] stdin=g, stdout=f)
的问题是它要求通过服务打开文件,而不是直接将它附加到python进程。您需要改为使用LIWC的路径。我不确定它是否支持从stdin
读取,因此您可能需要将路径传递给您希望打开的文件。