简体   繁体   English

如何使用子进程模块从python脚本运行AVL(二进制)?

[英]How do I run AVL (a binary) from a python script using the subprocess module?

I'm trying to script a series of runs in AVL (Athena Vortex Lattice) , a vortex lattice code for designing wings and other lifting surfaces. 我正在试图在AVL(Athena Vortex Lattice)中编写一系列运行,这是一种用于设计机翼和其他升力表面的涡旋格子代码。

I have the binary stored in ~/bin/. 我把二进制文件存储在〜/ bin /中。 Typically you run AVL within a terminal, and enter commands. 通常,您在终端中运行AVL,然后输入命令。 Typical commands would be: 典型的命令是:

  1. LOAD ~/path/avlexamplefile.avl LOAD~ / path / avlexamplefile.avl
  2. OPER OPER
  3. AA 5 AA 5
  4. X X
  5. FS FS
  6. RETURN 返回
  7. QUIT 放弃

Which, loads a .avl input file, enter the operations menu, sets the angle of attack to 5 degrees, executes the computation, Prints out the forces to an output file, exits the operations menu, and quits the program. 其中,加载.avl输入文件,进入操作菜单,将攻角设置为5度,执行计算,将力打印到输出文件,退出操作菜单,退出程序。

I'm trying to run AVL from a python script using the subprocess module using the following code: 我正在尝试使用以下代码使用子进程模块从python脚本运行AVL:

    import subprocess as sp
    avl = sp.Popen(['~/bin/avl3.35'],
           stdin=sp.PIPE,stdout=None, 
           stderr=None, 
           universal_newlines=True)

    avl.communicate('LOAD ~/file/avlexamplefile.avl')

This almost works. 这几乎可行。 AVL loads, the first command is executed, but then I get the following error, and won't take any further commands. AVL加载,第一个命令被执行,但后来我得到以下错误,并且不会接受任何进一步的命令。

    AVL   c>  forrtl: severe (24): end-of-file during read, unit -4, file        stdin
    Image              PC                Routine            Line        Source             
    avl3.35            000000010A00F43B  Unknown               Unknown  Unknown
    avl3.35            000000010A00DBFE  Unknown               Unknown  Unknown
    avl3.35            0000000109FD5177  Unknown               Unknown  Unknown
    avl3.35            0000000109F8B426  Unknown               Unknown  Unknown
    avl3.35            0000000109F8AA39  Unknown               Unknown  Unknown
    avl3.35            0000000109FB61F3  Unknown               Unknown  Unknown
    avl3.35            0000000109EEECF3  Unknown               Unknown  Unknown
    avl3.35            0000000109E7130F  Unknown               Unknown  Unknown
    avl3.35            0000000109E6FC7C  Unknown               Unknown  Unknown
    libdyld.dylib      00007FFF8B1D95AD  Unknown               Unknown  Unknown

Can anyone point out what I'm doing wrong? 谁能指出我做错了什么? Eventually, I'd like to place the above inside a for loop for running through multiple variations. 最后,我想将上面的内容置于for循环中以运行多个变体。

Try using avl.stdin.write("your cmd here" +'\\n') . 尝试使用avl.stdin.write("your cmd here" +'\\n')

Working example using xfoil is here (not mine): 使用xfoil的工作示例在这里(不是我的):

https://github.com/Launchpad-McQ/Aileron-design/blob/master/design-aileron.py https://github.com/Launchpad-McQ/Aileron-design/blob/master/design-aileron.py

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

相关问题 如何使用 subprocess 模块将 csh 脚本转换为 python? - How do I convert a csh script to python using the subprocess module? 如何从批处理文件运行充当cmd实例的子进程的python脚本? - How do I run a python script, from a batch file, that acts as a subprocess of the cmd instance? 如何使用另一个交付中的子进程运行python脚本 - How to run python script using subprocess from another delivery 如何使用python子进程模块将正则表达式传递给pdfgrep? - How do I pass a regex to pdfgrep using the python subprocess module? 使用Python子流程模块时如何传递变量 - How do I pass variable when using Python subprocess module 如何从 python 脚本子进程运行 pytest - How to run pytest from a python script subprocess 在Python中使用子进程如何以管理员身份运行'openvpn'? - Using subprocess in Python how do I run 'openvpn' as administrator? 使用python中的子进程模块运行带命令行输入的lua脚本 - Using the subprocess module in python to run a lua script with command line inputs 需要使用子进程模块在 python 脚本中运行 AWK 命令 - Need to run AWK command in python script using subprocess module 如何使用 subprocess.Popen 将参数从 Python 传递给 R 脚本 - How do I pass an argrument to an R Script from Python using subprocess.Popen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM