简体   繁体   English

如何执行 Scitools 理解来自 python 的命令

[英]How to execute Scitools Understand commands from python

I want to execute Scitools Understand commands from python.我想从 python 执行 Scitools 理解命令。 It has its own shell which can be run using $ ./und and switches to und> .它有自己的外壳,可以使用$ ./und运行并切换到und> I want to run its commands from python.我想从 python 运行它的命令。 Any idea how can I do that?知道我该怎么做吗?

First you should consider using the Python API for Ada Understand.首先,您应该考虑使用 Python API 来了解 Ada。 This will be more comfortable than talking to the Understand console.这将比与理解控制台交谈更舒服。

But using the console application is also possible.但也可以使用控制台应用程序。 Ada Understand uses the standard input and output. Ada 理解使用标准输入和输出。 Assuming you use Linux I have just a small demonstration for this.假设您使用 Linux,我对此只有一个小演示。

create a file und.input with the contents使用内容创建一个文件 und.input

help
exit

And then exeucute this command然后执行这个命令

cat und.input | /opt/scitools/bin/linux64/und > und.output

This will create you the output into the file und.output.这会将您的输出创建到文件 und.output 中。

You will not do it through files.你不会通过文件来做到这一点。 With these files I just tried to give you evidence and a feeling that really the standard input and standard output is used.通过这些文件,我只是试图向您提供证据和感觉,即真正使用了标准输入和标准输出。 Knowing this, you need a way in Python to start a process and communicate to it over stdin and stdout.知道了这一点,您需要一种在 Python 中启动进程并通过标准输入和标准输出与其通信的方法。 The subprocess module is a way to implement this.子流程模块是实现这一点的一种方式。 But there may be alternatives.但可能有替代方案。

Although my demonstration above is on Linux, the Python implementation with subprocess will be the same for Windows.尽管我上面的演示是在 Linux 上进行的,但带有子进程的 Python 实现对于 Windows 是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM