0

I had a look in many different answers, but none of them solve my problem.

I'm writing a python script to run an external software (written in fortran and compiled) that thakes itself some arguments.

This is the structure of the folder:

a.out (-> the compiled and running software)
zbtest.lst
zbtest.bud
zbtest.nam

In a normal shell session, when running ./a.out the program starts and ask me in sequence the zbtest.lst, zbtest.bud, zbtest.nam files.

Now, how can I concatenate the command that runs the compiled software and give in sequence the file asked?

Once in the correct directory and after reading many answers, I tried with:

import subprocess
subprocess.Popen('./a.out ; zbtest.lst ; zbtest.bud ; zbtest.nam', shell = True)

but it seems that only the first argument is taken (./a.out). The prompt of the software runs well, but it keeps asking me the 3 files listed.

I have no idea how to do that..

Thanks!

matteo
  • 4,683
  • 9
  • 41
  • 77
  • 1
    If your external program is only controllable by an interactive session and not by parameters, I would use `pexpect` (https://pexpect.readthedocs.org/en/stable/) to control the external program instead of `subprocess`. Then you can provide interactive input to your external program. – Salo Nov 02 '15 at 14:54
  • Does the following work in your normal shell?: `echo 'zbtest.lst\nzbtest.bud\nzbtest.nam' | ./a.out`, except with `\n` representing an actual newline you type by pressing the enter key? – Mad Physicist Nov 02 '15 at 14:56
  • @Salo, I didn't know this python module. The problem is that all the script I'm writing are part of a plugin. The aim is to use python as simple as possible without installing additional software, even if this is simply installable through pip... Anyway, thanks! – matteo Nov 02 '15 at 14:57
  • @MadPhysicist.. Well, it seems something is happening.. :) I'll do some more test about it.. – matteo Nov 02 '15 at 15:04
  • @MadPhysicist.. Not so simple to port it in a Win OS.. – matteo Nov 02 '15 at 16:11
  • @matteo. I agree that porting a pipe onto Windows may not be trivial. I am just suggesting that the pipe is a better model for what you are doing interactively than trying to pass multiple commands to the shell. – Mad Physicist Nov 02 '15 at 16:26

0 Answers0