我需要从Python启动一个子进程,然后向I发送命令

2024-04-24 21:15:24 发布

您现在位置:Python中文网/ 问答频道 /正文

o

就这么定了。我有一些python代码需要与我可以访问的特定matlab脚本进行交互。我可以通过以下操作轻松启动matlab:

import subprocess

self.farc = subprocess.Popen("xterm -e matlab -nosplash -nodesktop", shell = True, stdin = subprocess.PIPE)

一切都很好。但是,当我尝试将命令发送到matlab时,即:

command = "matlab_function" +"(" + "\'" + argument_from_python_code + "\'" +")"
self.farc.communicate(input = command)

我的程序和matlab终端都冻结了。几秒钟后,linux确定窗口没有更新并终止应用程序。你知道吗

有什么想法吗?你知道吗


Tags: 代码importself脚本truestdinshellcommand