Pedro Guillem
Pedro Guillem

Reputation: 53

python subprocess.call making program stop after second execution

I'm generating a text file that is later processed by an external program. This must be done 1000 times, for this, i use a subprocess.call() inside a loop for each text file i want to process.

The first call of subprocess.call() works perfectly.

The second call fails and the python program exits with a []Stop.

- There is no debug output. - Both remain stopped, but in the process list

I have tried subprocess.call(), subprocess.Popen() and the outcome is the same. I have tried to run it with the same textfile as the first execution and it also fails, so the culprit is the subprocess.call() function for sure.

This is the line that calls the external program

subprocess.call(['/bin/bash', '-i', '-c', 'nucplot textfile.txt']);

The program is a simple binary file, but it must use the ENV variables of its installation to work properly, hence the usage of /bin/bash with those options. If I try using a shell, it doesn´t work.

Is there anything else i need to do after calling subprocess.call() in order for it to flush its internal stuff?

Upvotes: 2

Views: 630

Answers (1)

Anirudh Panchangam
Anirudh Panchangam

Reputation: 498

Try using subprocess.check_output

https://docs.python.org/3/library/subprocess.html#subprocess.check_output

_ = subprocess.check_output(['/path/to/nucplot', '-i', '-c', 'textfile.txt'])

Upvotes: 1

Related Questions