Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture process output into history window #31

Closed
prjemian opened this issue Apr 20, 2017 · 3 comments · Fixed by #32
Closed

capture process output into history window #31

prjemian opened this issue Apr 20, 2017 · 3 comments · Fixed by #32
Milestone

Comments

@prjemian
Copy link
Contributor

when a process is run now, its output goes to the console

Capture that and add to history window

@prjemian
Copy link
Contributor Author

@prjemian
Copy link
Contributor Author

Capture is working on Windows but not on Linux for processes that do not immediately return a response, such as caQtDM startup. Looks as if those process quit early; caQtDM does not start. When the caQtDM starter fails here's how:

  1. bcdamenu executes configured command which is an external bash shell script in this case
  2. the shell script has two lines, a cd command and an internal start bash shell script command
  3. the process launched by bcdamenu fails when it reports it cannot find that internal script

But the external script command works both from the command line and from subprocess.Popen().

So, revert back to the subprocess.Popen() and try to grab all console output from the bcdamenu session (all subprocesses) using this (or a variation):

class Capture_stdout(list):
    '''
    capture all printed output (to stdout) into list
    
    # http://stackoverflow.com/questions/16571150/how-to-capture-stdout-output-from-a-python-function-call
    '''
    def __enter__(self):
        sys.stdout.flush()
        self._stdout = sys.stdout
        sys.stdout = self._stringio = StringIO()
        return self

    def __exit__(self, *args):
        self.extend(self._stringio.getvalue().splitlines())
        del self._stringio    # free up some memory
        sys.stdout = self._stdout

and calling it with something such as:

        with Capture_stdout() as printed_lines:
            do_something_that_writes_stdout()

then print(printed_lines) or such

see: http://stackoverflow.com/questions/16571150/how-to-capture-stdout-output-from-a-python-function-call

prjemian added a commit that referenced this issue Apr 21, 2017
prjemian added a commit that referenced this issue Apr 21, 2017
@prjemian
Copy link
Contributor Author

The correct way to do this is to make the history panel be a View of the history text buffer (the Model). As the model is updated, the view will refresh.

prjemian added a commit that referenced this issue Apr 22, 2017
prjemian added a commit that referenced this issue Apr 23, 2017
prjemian added a commit that referenced this issue Apr 23, 2017
yet, some processes (such IOC console status) do not start:

    starting /home/prjemian/Documents/eclipse/bcdamenu/runner.py ...
    (re)load settings: /home/prjemian/bin/bcdamenu.ini
    BcdaMenu (2017-04-23 11:38:41.663257), IOC status:  export
EPICS_HOST_ARCH=linux-x86_64; cd
/opt/epics/synApps/support/xxx-R5-8-3/iocBoot/iocLinux; ./xxx.sh status
    state: 1
    pid: 30278
    error: id_1
    state: 0
    error string: No such file or directory
    last error code: 0
    exitCode: 255
    exitStatus: 0
prjemian added a commit that referenced this issue Apr 24, 2017
prjemian added a commit that referenced this issue Apr 24, 2017
prjemian added a commit that referenced this issue Apr 24, 2017
@prjemian prjemian modified the milestone: 2017.4.0 Apr 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant