-1

I'm currently dealing with some python based squish gui tests. Some of these tests call another tool, written in c++ and build as an executable. I have full access to that tool and I'm able to modify it. The tests call it via command line and currently evaluate the error code and create a passed or failed depending on the error codes value. I think there is a better way to do it or? One Problem is, that the error code is limited to uint8 on unix systems and I would like to be able to share more than just an error code with my python script.

My first idea was printing everything in a file in json or xml and read that file. But this somehow sounds wrong for me. Has anybody a better idea?

Schere
  • 35
  • 5
  • having your c++ program print out xml or json is quite a standard and acceptable technique. The only difficulty is ensuring that nothing else in your program prints anything on the same stream and corrupts your output – Alan Birtles Sep 14 '18 at 06:57
  • XML will do the job nicely. – Tom Sep 14 '18 at 08:29
  • what about piping? make your c++ program write to cout and your python read from cin. Something like this: https://stackoverflow.com/questions/36748829/piping-binary-data-between-python-and-c –  Sep 14 '18 at 09:19

2 Answers2

0

When I first read the question, I immediately thought piping the output would work. Check this link out to get a better idea:

Linux Questions Piping

If this doesn't work, I do think writing your output to a file and reading it with your python script would get the job done.

0

You can capture the output of the external process via Python and process it as you see fit.

Here is a very simple variant:

import os
import subprocess

def main():
    s = os_capture(["ls"])
    if "ERROR" in s:
        test.fail("Executing 'ls' failed.")

def os_capture(args, cwd=None):
    if cwd is None:
        cwd = os.getcwd()
    stdout = subprocess.Popen(
        args=args,
        cwd=cwd,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT).communicate()[0]

    return stdout
frog.ca
  • 684
  • 4
  • 8