0

I have a C++ program which prints some data, but I call the program from my python script (I have performed boost python integration). But now I want to read the data which I have generated, from the same python script, but I just don't know how (new to Python).

I tried some recommendation from stack overflow such as

import subprocess
command = ['ls', '-l']
p = subprocess.Popen(command, stdout=subprocess.PIPE, 
stderr=subprocess.IGNORE)
text = p.stdout.read()
retcode = p.wait()

but the compiler throws an error module 'subprocess' has not attribute 'IGNORE'

Maybe I have compatibility issues with my current version of Python. I use Python 3.6.7 environment installed with Microsoft Visual Studio 2019. Can it be one of the reasons?

The data I need to read looks like this on the command prompt:

sol1=3.14789865446, .............................. (6 float values)
sol2=4.68909927756, .............................. (6 float values)
.
.
.
.
sol7=0.64527278288, .............................. (6 float values)
  • 1
    I never heard of subprocess.IGNORE in python? In which version do you actually use that? What exactly do you want to happen? I guess you want to use subprocess.DEVNULL – Mack123456 Aug 08 '19 at 21:18
  • @Mack123456 It was mentioned here https://stackoverflow.com/questions/8217613/how-to-get-data-from-command-line-from-within-a-python-program. I am using this in Python 3.6 – Prashanth Kumar H S Aug 08 '19 at 21:21
  • @Mack123456 I used DEVNULL as well. I got the error system cannot find the file specified – Prashanth Kumar H S Aug 08 '19 at 21:22
  • @Mack123456 I just want to read data printed by the python script on the command prompt. I am trying to do that in the same python script. Like the script generates some data and then reads the same data. – Prashanth Kumar H S Aug 08 '19 at 21:27
  • /dev/null on windows is the file 'nul'; see answer https://stackoverflow.com/a/6735958/362792 So where you try IGNORE you can use `open('nul','w')` instead – Hitobat Aug 08 '19 at 21:29
  • try without stdout and stderr >> .Popen(command) and see what happens – Mack123456 Aug 08 '19 at 21:33
  • @Hitobat I tried that. No error is being generated, but I am not able to access that data. Like I want to print the same data again. I tried print(f) but I can't see anything on command prompt – Prashanth Kumar H S Aug 08 '19 at 21:36
  • @Mack123456 I am getting error system cannot find the file specified – Prashanth Kumar H S Aug 08 '19 at 21:38
  • @Mack123456 AttributeError: 'NoneType' object has no attribute 'read' and 'ls' is not recognized as an internal or external command, operable program or batch file. – Prashanth Kumar H S Aug 08 '19 at 21:49
  • 1
    There is no `subprocess.IGNORE` in either Python 2,7 or 3.7.4. – martineau Aug 08 '19 at 22:00

0 Answers0